I have an assignment due for my Assembly class and I have a quick couple of questions regarding it.

The requirement is initialize 3 variables as 16bit words with values (10, -60, 30) add those values as the following equation y = var1 + var2 + var3, use no more than 3 lines of code to produce results. Show results in EAX register.

Question #1: The professor gave us nothing to go off of to ensure we have our code done correctly, so can someone give me the display of the EAX register as it should display if I accomplish the above correctly? (no code, just a screen shot of the output).

Here is the code I have so far:

.data
arrayD WORD 10, -60, 30

.code
mov esi, OFFSET arrayD
add eax, [esi]
add eax, [esi]
add eax, [esi]

call DumpRegs
call WaitMsg

exit

As you can see I have 4 lines of code to produce the results (at least I'm assuming the output is correct). What am I missing that would allow me to drop 1 line of code?

Thanks.

Oh and I realize there is lines missing from the above code, I left them out intentionally since they weren't relevant to my questions.

Edited 7 Years Ago by RayvenHawk: n/a

Ok I modified the code as follows, is there any problem with it?

.data
      arrayD WORD 10,-60,30

.code
       mov esi,OFFSET arrayD
       add eax,[esi+esi+esi]

       call DumpReg
       call WaitMsg

       exit
.data
      arrayD WORD 10, -60, 30
      .code
      mov esi, OFFSET arrayD
      mov ax, [esi+0] ; AX=10 initialize AX to value of
                                ; first word
      add ax, [esi+2] ; AX=AX + -60 = -50
      add ax, [esi+4] ; AX=AX + 30 = -20
      call DumpRegs
      call WaitMsg
      exit

In your original code you used the Extended 32-bit EAX
register for adding these 16-bit words, this would
cause it to treat two words at a time as a single value.
I believe MOVZX is the only MOVe which can use
two different datatypes.
MOV AX, [ESI] ; moves a word into AX
MOV EAX, [ESI] ; moves a dword into EAX
MOVZX EAX, BYTE PTR [EBX] ; move byte zero-extended into EAX
Every instruction needs complementary datatypes.
1111111111101100
AX=FFEC = -20

Good day.

IF ESI=OFFSET ARR and Addr ARR=00000100h
[ESI+ESI] -> DS:00000200h 256 bytes past first byte of array

This article has been dead for over six months. Start a new discussion instead.