assembly to compare two numbers

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

           ; 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.

提交回复
热议问题