Professional Documents
Culture Documents
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
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
.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
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
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
ANS:copiesFFineverybyteofthestring;Noerrorfound