0

I am currently learning to program in the 8085 microprocessor. Take a look at the program below:

LXI H, 2050
MOV B, M
INX H
MOV C, M
MVI A 00H
TOP: ADD B
DCR C
JNZ TOP
INX H
MOV M, A
HLT

This program multiplies two 8-bit numbers in the 8085 microprocessor. I know 'LXI H, 2050' has the hexadecimal operation code (opcode) '21, 50, 20'. In place of 'TOP: ADD B' and 'JNZ TOP', what opcode should I write, and what is the opcode for statements with labels in general?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Arya
  • 54
  • 8

1 Answers1

3

There is no opcode for a label itself. The assembler translates labels into addresses when you reference them from other places.

TOP: ADD B will be translated simply to 80, just as if the label wasn't there. The label address is the address where the 80 goes, the current position in the output for that line.

If, for example, this location is at address 1000H, JNZ TOP translates to C2 00 10.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • So how do I find out the address of the ADD B instruction? I'm confused – Arya May 05 '22 at 07:24
  • By compiling the program. Normally a compiler will do two passes: once to figure out what the instructions are and how big everything is; then it figures out where all the labels' targets are, and fix the addresses accordingly. You can do the same thing manually. `TOP:` is not part of the machine code: it is just a bookmark for the compiler to know what address to put in when it translates `JNZ TOP`. – Amadan May 05 '22 at 07:28
  • Since the compiler fixes the addresses, I need not enter the address of the label? – Arya May 05 '22 at 07:30
  • I believe I already answered: if the instruction labeled as `TOP:` lands at `1000H`, then the code for `JNZ TOP` is equal to `JNZ 1000H`: `C2 00 10`. You can see where the instruction ends by counting instruction sizes, and knowing where the code will start. `LXI H` takes 3 bytes, `MOV B, M` is 1, just like the next two instructions, and `MVI A` is 2. This means `TOP` will be 8 bytes after the address of the first instruction. – Amadan May 05 '22 at 07:35
  • Brilliant, thank you! I got it cleared now – Arya May 05 '22 at 07:37