Assembly programming
Platinum
May 23, 2003 11:02 PM |
Hi,
I am doing some assembly programming, but now I have hit a few problems. Could anybody help? (Please be aware that I am programming for the Motorola MC68K processor. I am using an emulator to test it.)
Ok, for starters, I'm using some sub-routines:
Start ORG $1000
MOVE.L #$7FFE,SP Init SP
MOVE.L #numbers,A3 Refer numbers to A3
MOVE.L #equal,A4 Refer string to A4
SUB.L #4,SP return input space (subroutine)
Then, I'm using the program to get six numbers from a user, and add them (Tdon't seem to add properly.):
* Get 6 numbers from user
Enter_key CMP.B #6,inc If the counter is 6, add numbers
BEQ Add_numbers If 6, go to Add_numbers
MOVE.B #247,D7 Get ready to get a char
TRAP #14 Get it
MOVE.B #248,D7 Get ready to display
TRAP #14 Displayed
MOVE.B (A3),D3 Copy D3,A3
MOVE.B D0,(A3)+ Increment numbers
ADD.B #1,inc Increments the letter-counter
BRA Enter_key Loop
* Loop and add
Add_numbers CLR.B inc Reset counter
Loop1 CMP.B #6,inc Check counter
BEQ Sign If counter is 6, show result
MOVE.B (A3)+,D1 Move A3 to D1
SUB.B #$30,D1
ADD.B D1,result Add number to result
MOVE.B D0,(A3)+ Increment numbers
ADD.B #1,inc Increment counter
BRA Loop1 Do it again
Then it takes the result of the addition and prints it on-screen in hex format (This is bit is giving me heaps of problems, and the subroutines don't seem to work):
* Print equals sign
Sign MOVE.B equal,D0 Put equal in D0
MOVE.W equal,-(SP) Put equal on SP, it doesn't seem to work though!
BSR Outch Go to Outch and print on-screen
* Print result in hexadecimal
Result MOVE.B result,D0 Put result in D0
MOVE.B D0,D1 Copy D0 into D1
LSR.B #4,D0 Shift bits 4-7 into bits 0-3
MOVE.W D0,-(SP) Push D0 (first digit)
BSR IF Go to start of the IF subroutine
AND.B #$0F,D1 Next digit (out of two)
MOVE.B D1,D0 Copy D1 to D0
MOVE.W D0,-(SP) Push D0 onto SP
BSR IF Branch to subroutine
Exit MOVE.W #228,D7 Get ready to exit
TRAP #14 Exited
Outch MOVE.W 4(SP),D0 Get parameter to print
MOVE.W #248,D7 Get ready to print it
TRAP #14 Print it
RTS Return (no answer needed to be returned)
* Convert
IF MOVE.W 4(SP),D0 Get parameter to change
CMP.B #9,D0 See if D0 is 9 or less
BHI ELSE If less go to ELSE
THEN ADD.B #$30,D0 Add $30
BRA Print_it Print result
ELSE ADD.B #$37,D0 Or add $37 for numbers bigger than 9 (A)
Print_it MOVE.W D0,-(SP) Push D0 onto SP
BSR Outch Goto subroutine
RTS
Finally, the data for the program:
Data ORG $5000 Starts at $5000
numbers DS.B 6 Give six spaces for numbers
inc DC.B 0 Increment letter counter
result DC.B 0 Put room for result
equal DC.B '=',if
if EQU $0A Define a line feed
END
This program, when put together, compiles fine. However, I am getting a Bus Trap Error, and I cannot for the life of me figure out why.
Thanks in advance,
Platinum |
Platinum
May 26, 2003 5:04 AM |
Hi,
Managed to iron out those problems.
Platinum
P.S. It's amazing that it takes that many lines to do something as simple as add 6 letters, and print them in hex. |
|
Posting in this forum is limited to members of the group: SITEADMINS, SUBSCRIBERS, MEMBERS.]
|

| If you don't have an account yet, visit the registration page to sign up. If you already have an account, you may login here:
|
|
|
Welcome to the Open Forums!!
|
Welcome to the Open Forums!!
|
|
|