Dividing in Assembler x86

前端 未结 4 1753
余生分开走
余生分开走 2020-12-22 10:10

My college gave me a exercise:

1. Create a new document in Jasmin

2. Use the AL-Register to to add 9 to 8.

3. Subtract 2.

4条回答
  •  Happy的楠姐
    2020-12-22 10:47

    div operation divides (unsigned) the value in the AX, DX:AX, or EDX:EAX registers (dividend) by the source operand (divisor) and stores the result in the AX (AH:AL), DX:AX, or EDX:EAX registers.

    source

    so, to divide value in al, you need to do:

    mov ah, 0 # clean up ah, also you can do it before, like move ax, 9
    mov bl, 7 # prepare divisor
    div bl # al = ax / bl, ah = ax % bl
    

    after that al will contain quotient and ah will contain remainder

提交回复
热议问题