Arithmetic operation in Assembler

83 Views Asked by At

I'm in the beginning of studying assembler, and I need to calculate (x1+x2)/(x1*x2), and I'm totally don't understand how to do it. Here's my variation of solving, but my teacher says there's a better way to do it.

org 0000h
x1: equ 30h
x2: equ 31h
res_hi: equ 40h
res_lo: equ 41h
tmp_hi: equ 50h
tmp_lo: equ 51h
zero: equ 53h

step_1: mov a, x1   ;input data to acc
    add a, x2
    mov res_lo, a
    clr a
    mov acc.0, c        ;resend to lsb
    mov res_hi, a

step_2: mov a, x1
    mov b, x2
    mul ab
    mov tmp_hi, b
    mov tmp_lo, a
    mov zero, #0

step_3: clr c 
    mov a, res_lo
    subb a, tmp_lo
    mov res_lo, a
    mov a, res_hi
    subb a, res_hi
    mov res_hi, a
    jc step_4
    inc zero
    sjmp step_3

step_4: ret
0

There are 0 best solutions below