You are on page 1of 1

Task 1:

Write a program, take two 8-bit numbers of your choice, perform subtraction them and display the
result.

Task 2:

Write a program, take two 16-bit numbers of your choice, perform subtraction them and display the
result.

; Input: AL = input number


; Output: AL = BCD

pushf ; Save flags register


push cx ; Save general-purpose regs
push dx
push ax
sub ah, ah ; We don't want a high-order byte
; so we don't have a divide overflow
mov dl, 0Ah ; Divide by 10
div dl ; Unsigned divide. Quotient in al,
; remainder in ah.
mov dl, ah ; Save remainder
mov ah, al ; Move quotient (multiple of 10)
mov cl, 4 ; and shift into high nibble of al
shr ax, cl ; (IA16 imposes stupid restrictions on shr operands)
or al, dl ; Set low nibble of al to remainder
pop dx ; Recover ah (pulling its value
mov ah, dh ; into dx first), cx, dx and flafs
pop cx
pop dx
popf
ret ; All done.

You might also like