You are on page 1of 5

CS422- Lab 12

Jeevan Surya Maddu


1401CS24
PRINCE RAHEJA
13-10-2017
1401CS37

P1_1
Indirect operands are ideal tools for stepping through arrays.
Find the content of AL after executing the following

.data
arrayBBYTE10h,20h,30h
.code
movesi,OFFSETarrayB
moval,[esi];AL=10h
incesi
moval,[esi];AL=20h
incesi
moval,[esi];AL=30h

If we use an array of 16-bit integers, we add 2 to ESI to address each subsequent array
element:
Find the content of AX after executing the following each of the cases

Case1

.data
arrayWWORD1000h,2000h,3000h
.code
movesi,OFFSETarrayW
movax,[esi];AX=1000h
addesi,2
movax,[esi];AX=2000h
addesi,2
movax,[esi];AX=3000h

Case2

.data
arrayWWORD1000h,2000h,3000h
.code
movesi,OFFSETarrayW
movax,[esi];AX=1000h
movax,[esi+2];AX=2000h
movax,[esi+4];AX=3000h

Case3

.data
arrayDDWORD100h,200h,300h,400h
.code
movesi,3*TYPEarrayD;offsetofarrayD[3]
moveax,arrayD[esi];EAX=00000400h
P1_2

myBytes BYTE 10h,20h,30h,40h


myWords WORD 8Ah,3Bh,72h,44h,66h
myDoubles DWORD 1,2,3,4,5
myPointer DWORD myDoubles

Fill in the requested register values on the right side of the following instruction sequence:
movesi,OFFSETmyBytes
moval,[esi];a.AL=10h
moval,[esi+3];b.AL=40h
movesi,OFFSETmyWords+2
movax,[esi];c.AX=003Bh
movedi,8
movedx,[myDoubles+edi];d.EDX=3
movedx,myDoubles[edi];e.EDX=3
movebx,myPointer
moveax,[ebx+4];f.EAX=2

Fill in the requested register values on the right side of the following instruction sequence:
movesi,OFFSETmyBytes
movax,[esi];a.AX=2010h
moveax,DWORDPTRmyWords;b.EAX=003B008Ah
movesi,myPointer
movax,[esi+2];c.AX=0000h
movax,[esi+6];d.AX=0000h
movax,[esi4];e.AX=0044h

P1_3: Indentify the function the following and content of rax.

.data
intarrayQWORD1000000000000h,2000000000000h
QWORD3000000000000h,4000000000000h
.code

movrdi,OFFSETintarray;RDI=addressofintarray
movrcx,LENGTHOFintarray;initializeloopcounter
movrax,0;sum=0
L1:;markbeginningofloop
addrax,[rdi];addaninteger
addrdi,TYPEintarray;pointtonextelement
loopL1;repeatuntilRCX=0
movecx,0;ExitProcessreturnvalue

ANS:

Theabovefunctionisusedtocalculatethesumofintegersintheintarray.

ContentsofRAX:
rax:0,rcx:4
rax:1000000000000h,rcx:3
rax:3000000000000h,rcx:2
rax:6000000000000h,rcx:1
rax:A000000000000h,rcx:0

P1_4

What value will RCX contain after executing the following instructions?
movrcx,1234567800000000h
subecx,1;RCx=12345678FFFFFFFFh

movrcx,1234567800000000h
addrcx,0ABABABABh;RCx=12345678ABABABABh.

What value will the AL register contain after executing the following instructions?
.data
bArrayBYTE10h,20h,30h,40h,50h
.code
movrdi,OFFSETbArray
decBYTEPTR[rdi+1]
incrdi
moval,[rdi]

AL= 1Fh

What will EAX contain after the following instructions execute?


.data
.dValDWORD?
.code
movdVal,12345678h
movax,WORDPTRdVal+2
addax,3
movWORDPTRdVal,ax
moveax,dVal

ANS:

EAX=12341237h

P_5

Write a program that uses the variables below and MOV instructions to copy the value from
bigEndian to littleEndian, reversing the order of the bytes. The numbers 32-bit value is
understood
to be 12345678 hexadecimal.
.data
bigEndianBYTE12h,34h,56h,78h
ANS:littleEndianDWORD78563412h

P_6

Write a program with a loop and indexed addressing that exchanges every pair of values in an
array with an even number of elements. Therefore, item i will exchange with item i+1, and item
i+2 will exchange with item i+3, and so on.

ANS:

.data
intarray DWORD 10000h,20000h,30000h,40000h
.code

mov edi,OFFSET intarray ; 1: EDI = address of intarray


mov ecx,LENGTHOF intarray ; 2: initialize loop counter
L1: ; 3: mark beginning of loop
mov eax,[edi]
Xchg eax,[edi+1] ; 4: exchange elements
Mov [edi],eax
add edi,2*TYPE intarray ; 5: increment edi
loop L1 ; 6: repeat until ECX = 0
exit

P_7: Partially complete procedure call is given. Find the output theSum

.data
arrayDWORD10000h,20000h,30000h,40000h,50000h
theSumDWORD?
.code
mainPROC
movesi,OFFSETarray;ESIpointstoarray
movecx,LENGTHOFarray;ECX=arraycount
callArraySum;calculatethesum
movtheSum,eax;returnedinEAX

mainENDP

;Receives:ESI=thearrayoffset
;ECX=numberofelementsinthearray
;Returns:EAX=sumofthearrayelements
;
ArraySumPROC
pushesi;saveESI,ECX
pushecx
moveax,0;setthesumtozero
L1:
addeax,[esi];addeachintegertosum
addesi,TYPEDWORD;pointtonextinteger
loopL1;repeatforarraysize
popecx;restoreECX,ESI
popesi
ret;sumisinEAX
ArraySumENDP
ENDmain

ANS: theSum=F0000h

P_8:Test the following, fix errors if any


.data
alphaBYTE"ABCDEFGH",0
.code
movedi,OFFSETalpha;EDIpointstothestring
moval,'F';searchfortheletterF
movecx,LENGTHOFalpha;setthesearchcount
cld;direction=forward
repnescasb;repeatwhilenotequal
jnzquit;quitifletternotfound
decedi;found:backupEDI
ANS:findslocationofF;Correctcode

P_9: Test the following, fix errors if any


.data
Count=100
string1BYTECountDUP(?)
.code
moval,0FFh;valuetobestored
movedi,OFFSETstring1;EDIpointstotarget
movecx,Count;charactercount
cld;direction=forward
repstosb;fillwithcontentsofAL

ANS:copiesFFineverybyteofthestring;Noerrorfound

P_10:Fill in the blanks


.data
arrayWORD1000h,2000h,3000h
.code
movebx,OFFSETarray
movesi,2
movax,[ebx+esi];AX=2000h
movedi,OFFSETarray
movecx,4
movax,[edi+ecx];AX=3000h
movebp,OFFSETarray
movesi,0
movax,[ebp+esi];AX=1000h

You might also like