0% found this document useful (0 votes)
27 views7 pages

Assemblyassignment

chapter 4 solution manual assembly

Uploaded by

ندى عايش
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

Assemblyassignment

chapter 4 solution manual assembly

Uploaded by

ندى عايش
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assembly lab

Computer Engineering department

Chapter 4 Assignment

Submitted by

Nada Ayesh 220200628

Submitted for

Eng Ola Harara

Due to Friday 13 sept 2024


Quick Notes : Questions will be in red , solutions will be under the solution word , question
parts are in pink the nal answer will be at bold at the nal step which will have a yellow
background . I write the answer at each question as steps to show how I reach the nal
answer by my own words and understanding (sorry if there is grammar or spelling issues I
didn’t check that to con rm everything is written by me and by my own understanding after
studying the chapter and not external resources)

Q3 page 134:
What will be the value in EAX after the following lines execute?
mov eax, 30020000h

dec ax

Solution:
1) since eax and the number are the same size the mov will happen
2) The twos complement of 00000000 00000001 after opposite one and zero ->11111111
11111110 and after adding one -> 11111111 11111111 which is ffffh

3) Since we are decrementing ax so just the lowest 16 bit will change


So we will add ffffh to 0000h -> the value will be ffffh
So the eax value is 3002ffffh

Q4 page 134:
What will be the value in EAX after the following lines execute?
mov eax,1002FFFFh

neg ax

Solution:

1) rst they are the same size so the mov will happen

2) Since the negate for the ax so the change will be just at ax

3) The twos complete of ffff -> which is in binary 11111111 11111111 -> 00000000
0000001-> 0001h (after opposite zero and ones and add one ) so the value of eax is

10020001h

Q6 page 134:
What will be the value of EAX and the Sign ag after the following lines execute?
mov eax,5

sub eax,6
Solution:
fi
fi
fi
fl
fi
fi
1) So here the value of eax is 00000005h at the rst line
2) Then the value 6 at 32 bit binary is
00000000 00000000 00000000 00000110 -> so the twos complement is
11111111 111111111 11111111 11111010 (after I opposite zero and one and add
one)

3) so after adding since the 5 is 101 it clear that the rst three lowest bits are 111 and the
remaining are ones also so this at hexadecimal is 0FFFFFFFFh
So the value of eax is FFFFFFFFh and since is negative the sign ag is 1

Q11 page 135:

.data
.dVal DWORD ?
.code
mov dVal,12345678h
mov ax,WORD PTR dVal+2
add ax,3
mov WORD PTR dVal,ax
mov eax,dVal

My line by line explanation to reach the nal answer:


1) the rst statement will happen since they are the same size so the value of dval is
12345678h

2) rst dval+2 since we use little endian it will point to the value 34 and well will take word
( 4 hexadecimal digits) from there so the value of ax will be 1234h

3) add ax,3 will be the value of ax 1237h since we add three to the previous value of ax

4) so the ax is 1237h and we want to move it to word PTR dval which means to the lowest
16 bit of the dval so the value of dval is 12341237h

5) then dval and eax are the same size so now eax is 12341237h

Q19 page 136:


Data used in the question :

.data
var1 SBYTE -4,-2,3,1
var2 WORD 1000h,2000h,3000h,4000h
var3 SWORD -16,-42
var4 DWORD 1,2,3,4,5
fi
fi
fi
fi
fi
fl
A) mov edx,var4;
Solution:
1) So var4 is DWORD which is suitable with 32 bit register edx so the move will happen
correctly.
2) The var4 is an array so the var4 will point to the rst element which is 1 so the value of
edx is 00000001h

B) movzx edx,var2;
Solution:
1) so we using movzx so its normal to have different sizes so here var2 is word and movzx
extends with zeros to t the destination size so here the rst lowest four bits will be var2
and the second will be zeros
2) So var2 is array so the var2 alone will points to the rst element at the array so the value
of edx will be 00001000h

C) mov edx,[var4+4];
Solution:
1) So var4 is DWORD which is suitable with 32 bit register edx so the move will happen
correctly.
2) var4+4 this will point to the second element in the var4 array why because we are using
DWORD so the offsets will be multiple of 4, so the value of edx is 00000002h

D) movsx edx,var1;
Solution:
1) So we using movzx so its normal to have different sizes so here var1 is byte and movsx
extends with something suitable with the sign which negative so it will continue with
ones (f because we using hexadecimal) to t the destination
2) Since var1 is array so it will point to the rst element which is -4
3) -4 to know the value of it at binary lets nd the twos complete of 00000100 which is
11111100(after I opposite zero and one and I add 1) which is at hexadecimal is 0FCh
4) So since its negative we will continue the value with f to t edx so the value will be
FFFFFFFCh

Q1 page 136:
1. Write a sequence of MOV instructions that will exchange the upper and lower words
in a double word variable named three

1) So the rst thing I started work on is translating the question suppose that this variable
for example is integer (it could be anything but this is easier for me) so the rst Lowest byte
will be at three then [three+1] will point to the second byte the [three+2] the third byte and
[three+3] is the fourth byte :

Lower word will be from three (three and [three+1])


fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
Upper word will be from three+2 ([three+2],[three+3]) and I will use word ptr to ensure
that I am taking a word from my correct start

2) so after I know what all be the upper and lower I will start loading into registers and swap

3) nal solution:

mov ax, word ptr three;

mov bx, word ptr [three+2];

mov word ptr three , bx;

mov word ptr [three+2] , ax

Q7 page 136:
1. Implement the following arithmetic expression in assembly language: EAX = –val2
+ 7 – val3 + val1. Assume that val1, val2, and val3 are 32-bit integer variables.

I will do it as steps explaining each step

1) First as what we learned with DR Ruba I will move the values at registers to not change
the original values :

mov eax , val1;

mov ebx,val2;

mov ecx ,val3;

2) negate the val2 :

neg ebx;

3) add 7 to val2:

Add ebx,7

4) sub val3 from the previous value :

sub ebx,ecx;

5) add val1 to the previous value

add ebx,eax;

6) mov eax,ebx;
fi
So the nal program

mov eax , val1;

mov ebx,val2;

mov ecx ,val3;

neg ebx;

add ebx,7;

sub ebx,ecx;

add ebx,eax;

mov eax,ebx;

Q13 page 137:


.data
myBytes BYTE 10h,20h,30h,40h
myWords WORD 3 DUP(?),2000h
myString BYTE “ABCDE"
A) mov eax,TYPE myBytes;
Solution:
So the type operator is the number of bytes that the variable use which is here one so the
value is 1

B) mov eax,LENGTHOF myBytes;


Solution:
The length is the number of elements at the array which is 4 so the value of eax is 4

C) mov eax,SIZEOF myBytes;


Solution:
The size is the length * type at the array which is 4*1 so the value of eax is 4

D) mov eax,TYPE myWords


Solution:
so the type operator is the number of bytes that the variable use which is here 2 so the value
of eax is 2

E) mov eax,LENGTHOF myWords


Solution:
The length is the number of elements at the array which is 4 three uninitalized and one
hexadecimal so the value of eax is 4
fi
F) mov eax,SIZEOF myWords;
Solution:
The size is the length * type at the array which is 4*2 so the value of eax is 8

G) mov eax,SIZEOF myString;


Solution:
The size is the length * type at the array which is 5*1 so the value of eax is 5

Acknowledgement:
I sincerely thank your efforts eng.Ola your discussions are incredible and the
assignment and the chosen of the question . The time and the effort you put is
truly inspiring thanks a lot

You might also like