Question: ;****Convert the following 32-bit Nasm (P5a.asm) program to 64 bit (P5a_64.asm). Skeletal code for (P5a_64.asm) is provided at the bottom. ; Output must be the
;****Convert the following 32-bit Nasm (P5a.asm) program to 64 bit (P5a_64.asm). Skeletal code for (P5a_64.asm) is provided at the bottom.
; Output must be the same for both, cannot change anything in .data section
; nasm -f elf32 P5a.asm && gcc -m32 -o P5a P5a.
extern printf
extern strlen
section .data
msg db "Testing:",0xA,0x0
len equ $ - msg
msg2 db "The length is: ",0x0
len2 equ $ - msg2
fmt db "%s",0xA,0x0
lfmt equ $ -fmt
fmt2 db "%u",0xA,0x0
lfmt2 equ $ - fmt2
t1 db "This is a test.",0x0
l1 equ $ - t1
t2 db "Newline test.",0xA,0x0
l2 equ $ - t2
t3 db 0xA,0x0
l3 equ $ - t3
t4 db 0x0
l4 equ $ - t4
section .bss
ta resd 4
retv resd 1
section .text
global main
main:
push ebp ; Save stack frame pointer
mov ebp, esp ; Setup a stack frame
; Setup tests
mov dword [ta], t1 ; 0
mov dword [ta+4], t2 ; 1
mov dword [ta+8], t3 ; 2
mov dword [ta+12], t4 ; 3
mov ecx, 3
loop:
mov esi, [ta+ecx*4]
push ecx ; Save ECX from potential clobbering
; printf(msg)
push dword msg ; Push the argument into the stack
call printf ; Call the function
add esp, byte 4 ; Clean the stack
; printf("%s ",ta)
push esi ; Push the argument into the stack
push dword fmt ; Push the argument into the stack
call printf ; Call the function
add esp, byte 8 ; Clean the stack
; retv = strlen(ta)
push esi ; Push the argument into the stack
call strlen ; Call the function
add esp, byte 4 ; Clean the stack
mov [retv], eax ; Save return value
; printf(msg2)
push dword msg2 ; Push the argument into the stack
call printf ; Call the function
add esp, byte 4 ; Clean the stack
; printf("%u ",retv)
push dword [retv] ; Push the argument into the stack
push dword fmt2 ; Push the argument into the stack
call printf ; Call the function
add esp, byte 8 ; Clean the stack
pop ecx
dec ecx ; Decrement counter
jns loop ; Jump while non-negative
mov esp, ebp ; Undo stack frame
pop ebp ; Restore stack frame pointer
mov eax, 0 ; main() return value
ret
;**************************************************************
;Following is P5a_64.asm skeletal code
; nasm -f elf64 P5a_64.asm && gcc -m64 -o P5a_64 P5a_64.o
extern printf
extern strlen
section .data
msg db "Testing:",0xA,0x0
len equ $ - msg
msg2 db "The length is: ",0x0
len2 equ $ - msg2
fmt db "%s",0xA,0x0
lfmt equ $ -fmt
fmt2 db "%u",0xA,0x0
lfmt2 equ $ - fmt2
t1 db "This is a test.",0x0
l1 equ $ - t1
t2 db "Newline test.",0xA,0x0
l2 equ $ - t2
t3 db 0xA,0x0
l3 equ $ - t3
t4 db 0x0
l4 equ $ - t4
section .bss
; add your bss section data here
section .text
global main
main:
; add your main code here
; some kind of loop, for every test message
; printf(msg)
; printf("%s ",ta)
; retv = strlen(ta)
; printf(msg2)
; printf("%u ",retv)
;**********************************
;Sample Output
Testing:
The length is: 0 Testing:
The length is: 1 -->a space is of length 1 Testing: Newline test.
The length is: 14 --> 14 spaces in the last example (NewLine test.) Testing:
This is a test. The length is: 15
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
