assembly to compare two numbers

前端 未结 8 1902
情书的邮戳
情书的邮戳 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 03:08

    First a CMP (comparison) instruction is called then one of the following:

    jle - jump to line if less than or equal to
    jge - jump to line if greater than or equal to

    The lowest assembler works with is bytes, not bits (directly anyway). If you want to know about bit logic you'll need to take a look at circuit design.

    0 讨论(0)
  • 2020-12-10 03:10

    It varies from assembler to assembler. Most machines offer registers, which have symbolic names like R1, or EAX (the Intel x86), and have instruction names like "CMP" for compare. And for a compare instruction, you need another operand, sometimes a register, sometimes a literal. Often assemblers allow comments to the right of instruction.

    An instruction line looks like:

    <opcode>   <register> <operand>   ; comment
    

    Your assembler may vary somewhat.

    For the Microsoft X86 assembler, you can write:

    CMP EAX, 23 ; compare register EAX with the constant 23

    or

    CMP EAX, XYZ ; compare register EAX with contents of memory location named XYZ

    Often one can write complex "expressions" in the operand field that enable the instruction, if it has the capability, to address memory in variety of ways. But I think this answers your question.

    0 讨论(0)
提交回复
热议问题