assembly to compare two numbers

前端 未结 8 1948
情书的邮戳
情书的邮戳 2020-12-10 02:35

What is the assembler syntax to determine which of two numbers is greater?

What is the lower level (machine code) for it? Can we go even lower? Once we get to the bi

8条回答
  •  遥遥无期
    2020-12-10 02:54

    In TASM (x86 assembly) it can look like this:

    cmp BL, BH
    je EQUAL       ; BL = BH
    jg GREATER     ; BL > BH
    jmp LESS       ; BL < BH
    

    in this case it compares two 8bit numbers that we temporarily store in the higher and the lower part of the register B. Alternatively you might also consider using jbe (if BL <= BH) or jge/jae (if BL >= BH).

    Hopefully someone finds it helpful :)

提交回复
热议问题