Tal
Tal

Reputation: 303

Question about ADD on ASM 8086

I'm studying ASM 8086 theoretically on highschool. (that means that I study ASM 8086 on a notebook, and never got to run it over 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 will happen if I do this:

MOV AH,F2h
ADD AH,20h

Thank you !!

Upvotes: 6

Views: 4093

Answers (4)

Macmade
Macmade

Reputation: 53930

MOV AL, F2h

Place the value 0xF2 in the AL (accumulator) 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 bits register, so the value will be 0x12, and not 0x112.

Same thing for AH, as it's also an 8 bits register.
To get the complete value, you will need to use the AX register, which is 16 bits.
AX is composed by AH (high) and AL (low), so you can access the high and low parts individually.

----------------EAX ----------------
                 ------- AX --------
|----------------|--------|--------|
|                |   AH   |   AL   |
|----------------|--------|--------|
     16 bits       8 bits   8 bits

Upvotes: 5

Skizz
Skizz

Reputation: 71060

I would also recommend using D86 (which comes with A86) as it lets you type in 8086 instructions interactively so you can see what happens to all the registers and flags after each instruction.

This code (as other have pointed out):

MOV AL, F2h
ADD AL, 20h

will only affect the flags and the AL register. No other eight-bit register will be affected (even AH). AX will change though since it is made up of AH and AL, so if AH was 42h:

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

The result of that particular operation will set the carry flag and the parity flag and clear the overflow, zero, sign and auxillary carry flags.

You may think that the overflow flag should be set, but the overflow flag treats the values as signed values (in this case -14 and 32) and the addition doesn't exceed the maximum signed value (127). The carry flag treats 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 carry is set.

Upvotes: 2

btk
btk

Reputation: 3225

My asm is a bit rusty.. but I think in your first instance, AL would hold 12h and the carry would increase AH by one.

Download this emulator, it will let you watch the execution of code step-by-step, inspect values of registers, etc. Much more fun than pencil-and-paper.

Upvotes: 0

wassertim
wassertim

Reputation: 3136

When I was studying ASM in school I used this program. It helped me a lot to debug simple asm programs. You just put your source code into editor, click debug and watch what happened with registers step-by-step

Upvotes: 0

Related Questions