My script take input of two numbers subtract the second number from the first and output the result:
CR EQU $0D
LF EQU $0A
START ORG $1000
*---------- Code for output ---------*
LEA MSG1,a1
MOVE.B #14,d0
TRAP #15
*---------- Code for input ---------*
MOVE.B #4,d0
TRAP #15
move.b d1,d2
*---------- Code for output ---------*
LEA MSG2,a1
MOVE.B #14,d0
TRAP #15
*---------- Code for input ---------*
MOVE.B #4,d0
TRAP #15
sub.b d2,d1
move #3,d0
trap #15
*---------- Halt Simulator ---------*
MOVE.B #9,d0
TRAP #15
* Stop execution
STOP #$2000
MSG1 DC.B 'Enter a first number: ',0
MSG2 DC.B 'Enter a second number: ',0
END START end of program with start address specified
If first number = 50
And second number = 100
Result is = 50
but if first number = 100
and second number = 50
Result is 206
Why is it 206? what is happening? and what is the significance of 256 in this operation.
Also very good resource that explains this is on the following link:
Let's perform the subtraction in hexadecimal on 1 byte:
32H - 64H = 00H - 32H = CEH (two's complement) with carry bit set to 1
CEH in hexadecimal = 206 in decimal
So your observed result is the expected one.