In: Computer Science
Please complete in MASM (x86 assembly language). Use the code below to get started.
Use a loop with indirect or indexed addressing to reverse the elements of an integer array in
place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF
operators to make the program as flexible as possible if the array size and type should be
changed in the future.
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO,dwExitCode:DWORD
.data
; define your variables here
.code
main PROC
; write your assembly code here
INVOKE ExitProcess,0
main ENDP
END main
Below is the assembly language code for inplace reversing of array.
daddiu $sp,$sp,-64
sd $fp,56($sp)
move $fp,$sp
lui $6,%hi(%neg(%gp_rel(main)))
daddu $6,$6,$25
daddiu $6,$6,%lo(%neg(%gp_rel(main)))
ld $2,%got_page(.LC0)($6)
daddiu $3,$2,%got_ofst(.LC0)
ldl $3,7($3)
ldr $3,%got_ofst(.LC0)($2)
move $4,$3
daddiu $3,$2,%got_ofst(.LC0)
ldl $5,15($3)
ldr $5,8($3)
move $3,$5
daddiu $2,$2,%got_ofst(.LC0)
ldl $5,23($2)
ldr $5,16($2)
move $2,$5
sd $4,16($fp)
sd $3,24($fp)
sd $2,32($fp)
li $2,6 # 0x6
sw $2,0($fp)
sw $0,4($fp)
lw $2,0($fp)
addiu $2,$2,-1
sw $2,8($fp)
.L3:
lw $3,4($fp)
lw $2,8($fp)
slt $2,$3,$2
beq $2,$0,.L2
nop
lw $2,4($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $2,16($2)
sw $2,12($fp)
lw $2,8($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $3,16($2)
lw $2,4($fp)
dsll $2,$2,2
daddu $2,$fp,$2
sw $3,16($2)
lw $2,8($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $3,12($fp)
sw $3,16($2)
Thank You.