0
votes

I have problem when I am subtracting two 16 bits numbers in assembler for i8080 processor.

Example: 0f70 - 00f0 and first number will be in registers B and C, second in D and E.

Binary:

B = 0000 1111 C = 0111 0000

D = 0000 0000 E = 1111 0000

So when I subtract C-E it need "borrow". Ok so I will decrement B but what about C? I know in this case C would be 1000 0000 but other cases?

Code:

    ORG 800H   
RST 5  
MOV B,D  
MOV C,E   //after this in B and C I have 16bit minuend
RST 5     //after this in D and E I have 16bit subtrahend
MOV A,C     //Move C to Accumulator 
SUB E       //subtract E
JC SUBTRACTINGB //if it don't need borrow jump
DCR B       //else decrement B
MVI C,?    // and what should be in C???
1
What about C? You don't have to fix it up or anything like that, borrow only goes towards higher bitsharold
Your question "what about C?" only makes sense to yourself. What about c? What about the weather? 1. Show your code. 2. Show the input and the output. 3. Show the expected output.Mike Nakis
Ok, you have part of my code with comments. Question "what about C " means what should I do with number from register C. Should I subtract sth, should I add sth? I know how to subtract binary numbers but it is little diffrent here.Adam A
It is actually not different here. The existence of higher bytes is irrelevant for the computation on the lower bytes, the borrow only travels upwards.harold

1 Answers

1
votes

No change to C is necessary. There is no borrow into the lowest byte, and the lowest byte borrowing has no consequences for its own value, it only means 1 more should be subtracted from the next byte.

You can do the conditional decrement automatically by using SBB:

; subtract low byte
mov a,c
sub e
mov c,a
; subtract high byte with borrow
mov a,b
sbb d
mov b,a