Article 4T7BV Integer Arithmetic Operations - subl

Integer Arithmetic Operations - subl

by
andrew.comly
from LinuxQuestions.org on (#4T7BV)
BACKGROUND:
I am trying to better understand assembly language, so I am reading the book Computer Systems, A Programmer's Perspective, by Randal E. Bryant David R. O'Hallaron, November 16, 2001.
I am having trouble understanding how to assign Source and Destination variables correctly, computing resultant addresses and values.
I have read to Chapter 3 subsection 3.5.2Unary and Binary Operations, and am stuck on applying "Fig 3.6 Integer Arithmetic Operations"(attached)'s 3rd group to solving Arithmetic Operations. I seem to be subtracting Incompatible types.

QUESTION: Practice Problem 3.4 -
Fill in the following table showing the effects of the following instructions, both in terms of the register or memory location that will be updated and the resulting value.
GIVEN:
Code:
Register Value
%eax 0x100
%ecx 0x1
%edx 0x3

Address Value
0x100 0xFF
0x104 0xAB
0x108 0x13
0x11C 0x11
PROBLEM 2)Code:subl %edx, 4(%eax)myAttempt:Assign (S)ource and (D)estination:
S = %edx; D = Several possibilities:
1) D = (Value held at the address in register %eax) +4
or
2) D = (Value held at the address in register %eax)
or
3) Something else?

The book gives the answers (Appendix B):
Code:Destination: 0x104
Value: 0xA8At first I interpreted the above equation as:
Code:D = D - S
%eax = 4(%eax) - %edxUp to now I have learned that parenthesis are very important: i.e.- (%eax) is a value, %eax is an address.
**Confusion) How can we add a value to an address?**
Anyway, I tried first figuring out the value for 4(%eax).
4(%eax)
Since %eax's value is 0x100 and %edx's address is 0x3, I compute:
Code:(%eax):
0x100
1*16^2 + 0*16^1 + 0*16^0
256 + 0 + 0
256
4(%eax):
256 + 4
260Then I tried to subtract the address located in %edx(0x3) from this.
But the value chart doesn't give us the value at 0x3, so I converted 0x3(hex) into decimal:
3
Then subtract it from above step:
Code:260 - 3 = 257.Which converts back to hex as 0x101.

How did they get their answer(above)??
Attached Thumbnailsattachment.php?attachmentid=31639&stc=1& attachment.php?attachmentid=31640&stc=1& latest?d=yIl2AUoC8zA latest?i=K759GDR3uXY:TPKAWfLvf94:F7zBnMy latest?i=K759GDR3uXY:TPKAWfLvf94:V_sGLiP latest?d=qj6IDK7rITs latest?i=K759GDR3uXY:TPKAWfLvf94:gIN9vFwK759GDR3uXY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments