Bishwajit Purkaystha
Bishwajit Purkaystha

Reputation: 2195

How 8086 assembler converts the label to opcode?

I was exploring the 8086 instruction set and was writing simple assembly codes in emu8086. I understood all the MOV,ADD, and other instructions until I encountered the LOOP instruction. The LOOP is converted to E2, that's fine. But for the label to branch, how does the assembler converts it? If the code is simple, many a times 'label' is converted to FC. Sometimes to FA, F8, and others. It would be very appreciable if you discuss the mechanism of converting the label name to its corresponding machine code.

Thanks.

Upvotes: 0

Views: 594

Answers (1)

Cyb3rFly3r
Cyb3rFly3r

Reputation: 1341

As explained on this page , the label is just a mnemonic for us (programmers). The assembler translates that label into a number, e.g. an offset to be added to the instruction pointer to jump to, while CX is not zero. In the examples you show, those offset are negative numbers (sign bit set to one). So it is jumping few instructions back, as you would expect in a loop.

Upvotes: 2

Related Questions