tags:

views:

65

answers:

4

Hello, 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 !!

A: 

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

Tim
WOW!I was looking for something like that for months!Thank you very much!!!
Tal
A: 

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.

btk
+3  A: 
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
Macmade
Since it's an 8bit register, will the carry flag be set?
xtofl
Yes, it will be set as there is an overflow of the AL register.
Macmade
Thank you very much Macmade, I understand now the basics of ASM much better. :-)
Tal
You're welcome : )
Macmade
Your diagram is wrong, AX is only 16 bits. On the 386 and above, the 32 bit register is called EAX, so in 32 bit code there are EAX, AX, AH and AL (but no way to address the upper 16 bits of EAX as a 16 bit value).
Skizz
Ooops, sorry for that... Corrected the diagram, thanx : )
Macmade
+1  A: 

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.

Skizz