Script started on Mon 26 Feb 2024 08:23:58 PM EST [mweeks@gsuad.gsu.edu@snowball ~]$ cat test_ea.asm ; Assemble: nasm -f elf64 test_ea.asm ; Link: gcc test_ea.o -o test_ea ; Based on AddTwoSum_64.asm (by Kip Irvine) ; This is adapted for NASM. extern printf ; We will use this external function section .data ; Data section, initialized variables mystr: db "%d", 10, 0 ; String format to use (decimal), followed by NL sum: dq 0 section .text global main main: mov rax,5 add rax,6 mov [sum], rax ; Now print the result out ;mov rdi, mystr ; Format of the string to print mov rdi, [mystr] ; causes a segmentation fault mov rdi, mystr ; ;mov rsi, [sum] ; Value to print mov rsi, sum ; Value to print - notice that the result is not 11 mov rax, 0 call printf mov rdi, mystr ; Format of the string to print mov rsi, [sum] ; Value to print mov rax, 0 call printf mov rax, 3 ret [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 test_ea.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc test_ea.o -o test_ea [mweeks@gsuad.gsu.edu@snowball ~]$ ./test_ea 6295608 11 [mweeks@gsuad.gsu.edu@snowball ~]$ cat mybytes.asm ; Assemble: nasm -f elf64 mybytes.asm ; Link: gcc mybytes.o -o mybytes ; Based on AddTwoSum_64.asm (by Kip Irvine) ; This is adapted for NASM. extern printf ; We will use this external function section .data ; Data section, initialized variables myBytes: db 80h,66h,0A5h mystr: db "%ld", 10, 0 ; String format to use (decimal), followed by NL sum: dq 0 section .text global main main: xor rax, rax ; A = 0 mov al,[myBytes] add al,[myBytes+1] add al,[myBytes+2] mov [sum], rax xor rax, rax ; A = 0 mov al,[myBytes] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 mov al,[myBytes+1] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 mov al,[myBytes+2] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf ; Now print the result out mov rdi, mystr ; mov rsi, [sum] ; Value to print mov rax, 0 call printf ; ; mov rdi, mystr ; Format of the string to print ; mov rsi, [sum] ; Value to print ; mov rax, 0 ; call printf mov rax, 0 ret [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 mybytes.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc mybytes.o -o mybytes [mweeks@gsuad.gsu.edu@snowball ~]$ ./mybytes 128 102 165 139 [mweeks@gsuad.gsu.edu@snowball ~]$ cat mybytes2.asm ; Assemble: nasm -f elf64 mybytes2.asm ; Link: gcc mybytes2.o -o mybytes2 ; Based on AddTwoSum_64.asm (by Kip Irvine) ; This is adapted for NASM. extern printf ; We will use this external function section .data ; Data section, initialized variables ;myBytes: db 80h,66h,0A5h ;myBytes: db 80h,0, 66h,0A5h myBytes: db 80h,0, 66h,0, 0A5h, 0 mystr: db "%ld", 10, 0 ; String format to use (decimal), followed by NL sum: dq 0 section .text global main main: xor rax, rax ; A = 0 mov ax,[myBytes] ;add ax,[myBytes+1] add ax,[myBytes+2] ;add ax,[myBytes+2] add ax,[myBytes+4] mov [sum], rax xor rax, rax ; A = 0 mov ax,[myBytes] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 ;mov ax,[myBytes+1] mov ax,[myBytes+2] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 ;mov ax,[myBytes+2] mov ax,[myBytes+4] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf ; Now print the result out mov rdi, mystr ; mov rsi, [sum] ; Value to print mov rax, 0 call printf ; ; mov rdi, mystr ; Format of the string to print ; mov rsi, [sum] ; Value to print ; mov rax, 0 ; call printf mov rax, 0 ret [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 mybytes2.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc mybytes2.o -o mybytes2 [mweeks@gsuad.gsu.edu@snowball ~]$ ./mybytes2 128 102 165 395 [mweeks@gsuad.gsu.edu@snowball ~]$ cp mybytes2.asm mybytes2_bad.asm [mweeks@gsuad.gsu.edu@snowball ~]$ vi mybytes2_bad.asm [mweeks@gsuad.gsu.edu@snowball ~]$ [mweeks@gsuad.gsu.edu@snowball ~]$ [mweeks@gsuad.gsu.edu@snowball ~]$ cat mybytes2_bad.asm ; Assemble: nasm -f elf64 mybytes2_bad.asm ; Link: gcc mybytes2_bad.o -o mybytes2_bad ; Based on AddTwoSum_64.asm (by Kip Irvine) ; This is adapted for NASM. extern printf ; We will use this external function section .data ; Data section, initialized variables myBytes: db 80h,66h,0A5h ;myBytes: db 80h,0, 66h,0A5h ;myBytes: db 80h,0, 66h,0, 0A5h, 0 mystr: db "%ld", 10, 0 ; String format to use (decimal), followed by NL sum: dq 0 section .text global main main: xor rax, rax ; A = 0 mov ax,[myBytes] ;add ax,[myBytes+1] add ax,[myBytes+2] ;add ax,[myBytes+2] add ax,[myBytes+4] mov [sum], rax xor rax, rax ; A = 0 mov ax,[myBytes] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 ;mov ax,[myBytes+1] mov ax,[myBytes+2] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf xor rax, rax ; A = 0 ;mov ax,[myBytes+2] mov ax,[myBytes+4] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf ; Now print the result out mov rdi, mystr ; mov rsi, [sum] ; Value to print mov rax, 0 call printf ; ; mov rdi, mystr ; Format of the string to print ; mov rsi, [sum] ; Value to print ; mov rax, 0 ; call printf mov rax, 0 ret [mweeks@gsuad.gsu.edu@snowball ~]$ echo This is a re-creation of what we saw in class. This is a re-creation of what we saw in class. [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 mybytes2_bad.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc mybytes2_bad.o -o mybytes2_bad [mweeks@gsuad.gsu.edu@snowball ~]$ ./mybytes2_bad 26240 9637 25708 61585 [mweeks@gsuad.gsu.edu@snowball ~]$ echo "See mybytes2.asm (above) for the fixed version" See mybytes2.asm (above) for the fixed version [mweeks@gsuad.gsu.edu@snowball ~]$ diff mybytes2.asm mybytes2_bad.asm 1,2c1,2 < ; Assemble: nasm -f elf64 mybytes2.asm < ; Link: gcc mybytes2.o -o mybytes2 --- > ; Assemble: nasm -f elf64 mybytes2_bad.asm > ; Link: gcc mybytes2_bad.o -o mybytes2_bad 11c11 < ;myBytes: db 80h,66h,0A5h --- > myBytes: db 80h,66h,0A5h 13c13 < myBytes: db 80h,0, 66h,0, 0A5h, 0 --- > ;myBytes: db 80h,0, 66h,0, 0A5h, 0 [mweeks@gsuad.gsu.edu@snowball ~]$ exit exit Script done on Mon 26 Feb 2024 08:30:10 PM EST