Question regarding output

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 57
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training

Question regarding output

 
0
  #1
Oct 22nd, 2009
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:

  1. .data
  2. arrayD WORD 10, -60, 30
  3.  
  4. .code
  5. mov esi, OFFSET arrayD
  6. add eax, [esi]
  7. add eax, [esi]
  8. add eax, [esi]
  9.  
  10. call DumpRegs
  11. call WaitMsg
  12.  
  13. 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.
Last edited by RayvenHawk; Oct 22nd, 2009 at 1:34 pm.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 57
Reputation: RayvenHawk is an unknown quantity at this point 
Solved Threads: 1
RayvenHawk RayvenHawk is offline Offline
Junior Poster in Training
 
0
  #2
Oct 22nd, 2009
Ok I modified the code as follows, is there any problem with it?

  1. .data
  2. arrayD WORD 10,-60,30
  3.  
  4. .code
  5. mov esi,OFFSET arrayD
  6. add eax,[esi+esi+esi]
  7.  
  8. call DumpReg
  9. call WaitMsg
  10.  
  11. exit
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."

Programmers - Making other people rich for over 50yrs.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 139
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #3
Oct 22nd, 2009
  1. .data
  2. arrayD WORD 10, -60, 30
  3. .code
  4. mov esi, OFFSET arrayD
  5. mov ax, [esi+0] ; AX=10 initialize AX to value of
  6. ; first word
  7. add ax, [esi+2] ; AX=AX + -60 = -50
  8. add ax, [esi+4] ; AX=AX + 30 = -20
  9. call DumpRegs
  10. call WaitMsg
  11. 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.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 139
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #4
Oct 22nd, 2009
IF ESI=OFFSET ARR and Addr ARR=00000100h
[ESI+ESI] -> DS:00000200h 256 bytes past first byte of array
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC