Question about ADD on ASM 8086

I study ASM 8086 theoretically in high school. (this means that I am learning ASM 8086 on a laptop and have never run it through a computer).

And I don’t understand what will happen if I do this:

MOV AL, F2h ADD AL, 20h 

What will the computer do? (what will be the value of AL, AX, CF, ZF?)

and what happens if I do this:

 MOV AH,F2h ADD AH,20h 

Thanks!

+6
assembly x86 add
source share
4 answers
 MOV AL, F2h 

Place the value 0xF2 in the AL (battery) register.

 ADD AL, 20h 

Adds the value 0x20 to the value contained in the AL register.

AL will be 0xF2 + 0x20. But AL is an 8-bit register, so the value will be 0x12, not 0x112.

The same goes for AH, as it is also an 8-bit register.
To get the full price, you will need to use the AX register, which is 16 bits.
AX consists of AH (high) and AL (low), so you can access the high and low parts separately.

 ----------------EAX ---------------- ------- AX -------- |----------------|--------|--------| | | AH | AL | |----------------|--------|--------| 16 bits 8 bits 8 bits 
+5
source share

I also recommend using D86 (which comes with A86) because it allows you to enter 8086 commands interactively so you can see what happens to all registers and flags after each instruction.

This code (as others have pointed out):

 MOV AL, F2h ADD AL, 20h 

will only affect AL flags and case. No other eight-bit register will be affected (even AH). AX will change because, because it consists of AH and AL, therefore, if AH was 42h:

 Code AL AH AX MOV AL,F2h F2 42 42f2 ADD AL,20h 12 42 4212 

The result of this particular operation sets the carry flag and the parity flag and clears the overflow, zero, sign, and auxiliary carry flags.

You might think that the overflow flag should be set, but the overflow flag processes the values ​​as signed values ​​(in this case -14 and 32), and the addition does not exceed the maximum signed value (127). The carry flag processes the values ​​as unsigned values ​​(242 and 32), and the addition exceeds the maximum unsigned value: 242 + 32 = 274, which is greater than 255, so the transfer is set.

+1
source share

When I studied ASM at school, I used this program. This really helped me debug simple asm programs. You just put your source code in the editor, click on "Debug" and see what happened with the step-by-step registers

0
source share

My asm is a little rusty .. but I think that in your first instance, AL will spend 12 hours and the transfer will increase AH by one.

Download this emulator, it will allow you to monitor code execution step by step, check register values, etc. Much more fun than pencil paper.

0
source share

All Articles