Help with memory/addresses in Assembly (Intel x86 + NASM)?
I'm taking my first Assembly class and the memory addresses/contents stuff is really confusing me. I was hoping someone who knows this stuff well could check my answers for these problems I need to know, and explain how to correct the wrong ones? (My answers will have *** in front of them)
1.) Suppose
si contains 0100h
ax contains 4142h
df = 0
byte 100h contains 10h
byte 101h contains 15h
byte 200h contains 20h
byte 201h contains 25h
Give the source, destination, and value moved for each of the following instructions:
a.) movsb
ANSWERS:
source = ***0100h
dest = ***200h
val moved = ***10h
si = ***15h
di = ***10h
b.) movsb
ANSWERS:
source = ***0100h
dest = ***200h
val moved = ***0010h
si = ***20h
di = ***30h
c.) stosb
ANSWERS:
source = ***al
dest = ***200h
val moved = ***42h
si = ***0100h
di = ***25h
d.) lodsb
ANSWERS:
source = ***0100h
dest = ***al
val moved = ***10h
si = ***15h
di = ***200h
c.) lodsw
ANSWERS:
source = ***0100h
dest = ***ax
val moved = ***0010h
si = ***20h
di = ***200h
:
2.) For each of the following instructions show what happens if:
ax contains 0500h
bx contains 1000h
si contains 1500h
di contains 2000h
[1000h] = 0100h
[1500h] = 0300h
[2000h] = 0600h
[3000h] = 0200h
[4000h] = 0400h
kats is a word variable whose offset address is 1000h
ANSWERS:
a.) mov di, si
***di now = 1500h
b.) mov ax, [si]
***ax now = 0300h
c.) lea si, [bx+kats]
***si now = 1100h (?)
d.) mov [si], [di]
***Illegal: Cannot perform memory to memory moves
e.) mov ah, [bx]
***Illegal: Cannot move 16 bits into 8 bits
f.) mov dh, [si]
***Illegal: Cannot move 16 bits into 8 bits
g.) mov cx, [bx+di+kats]
***cx now = 0800h (?)
Thanks for your time, I really appreciate it.
Best AnswerAsker's Choice
1. The value of di is missing. Is it 200h?
a) movsb
src = 100h
dst = 200h
value = 10h
c) stosb
src = al
dst = 200h
value = 42h
d)
src = 100h
dst = al
value = 10h
e) lodsw
src = 100h
dst = ax
value = 1510h
2.
a) correct
b) correct
c) nope. lea computes the effective address in the source operand but instead of reading the value from it assigns it to the destination register. The address of [bx + kats] is 2000h.
d) correct.
e) Nope. The size of the address (bx) is not related to the size of the value. mov ah, cx would be illegal because ah is 8-bit and cx is 16-bit.
f) Same here.
g) bx + di + kats = 1000h + 2000h + 1000h = 4000h, [4000h] is 400h therefore cx would be 0800h.
Asker's rating & comment
- Thank you so much for your response! You helped me out a lot, I did have a few follow up questions, if you don't mind?
(And yes, di = 200h)
For each of question 1.), it asks for the new contents of di and si, I get those wrong as well?
I didn't see b.) in the response, accidental overlook?
Alex answered 2 months ago You should try with debug.exe
It is not included anymore (MSDOS), but you can use FreeDOS from a USB drive or in a virtual machine. Some Windows versions can run it in command line.
Assembler is really hard and pain to do this exercize. I would not know correctly and I wrote assembler complete programs some kilobytes
Really actually using it is the only way to know correctly.
It is irrelevant if
***Illegal: Cannot move 16 bits into 8 bits
is illegal because it is a limit of x86 and not something worth to memorize. Download the AMD reference manuals or the IA32 Intel manuals as PDF and look at the MMX data shuffling- this is where it ends. Would you like to memorize it?
I tell you because I spent too much time with assembler on microcontrollers and now I regret it. You should learn C language as soon as possible.
Maybe if you have or can get an old laptop, install MSDOS or FreeDOS on it if you plan to learn assembler. I'd not recommend it for a start, maybe later if you mastered C.
C is also very close to assembler, but one remarkable thing, it gets rid of the particular limits of the instruction set- can't do this, can't do that, must shuffle registers all the time and stuff.
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。