; Guide to Assembly Language
; Section 11.9 Complete Program
; Copyright 2019, James T. Streib
printf PROTO
scanf PROTO
.data
msg1fmt byte "%s",0
msg2fmt byte 0Ah,"%s",0Ah,0Ah,0
msg3fmt byte " %lld", 0Ah,0Ah,0
in1fmt byte "%lld",0
msg2 byte "Enter an integer: ",0
msg3 byte "Reversed",0
n sqword 5
arry sqword 5 dup(?)
.code
main proc
mov rcx,n ; initialize rcx to n
mov rbx,0 ; initialize rbx to 0
for01: nop
push rcx ; save rcx
lea rcx, msg1fmt
lea rdx, msg2
sub rsp, 40
CALL printf
add rsp, 40
lea rcx, in1fmt
lea rdx,arry[rbx]
sub rsp,40
call scanf
add rsp,40
pop rcx ; restore rcx
add rbx,8 ; increment rbx by 8
loop for01
endfor01: nop
lea rcx, msg2fmt
lea rdx, msg3
sub rsp, 40
CALL printf
add rsp, 40
mov rcx,n ; initialize rcx to n
sub rbx,8 ; subtract 8 from rbx
for02: nop
push rcx ; save rcx
lea rcx, msg3fmt
mov rdx, arry[rbx]
sub rsp, 40
CALL printf
add rsp, 40
pop rcx ; restore rcx
sub rbx,8 ; decrement rbx by 8
loop for02
endfor02: nop
ret
main endp
end