Script started on Wed 28 Feb 2024 04:29:53 PM EST [mweeks@gsuad.gsu.edu@snowball ~]$ cat ptr.asm ; Assemble: nasm -f elf64 ptr.asm ; Link: gcc ptr.o -o ptr ; This is adapted for NASM. extern printf ; We will use this external function section .data ; Data section, initialized variables mystr: db "%x", 10, 0 ; String format to use (decimal), followed by NL myDouble: dd 12345678h section .text global main main: xor rax, rax ; A = 0 mov al, byte [myDouble] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf mov al,BYTE [myDouble+1] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf mov al,BYTE [myDouble+2] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf mov al,BYTE [myDouble+3] mov rsi, rax mov rax, 0 mov rdi, mystr ; call printf mov rax, 0 ret [mweeks@gsuad.gsu.edu@snowball ~]$ nasm -f elf64 ptr.asm [mweeks@gsuad.gsu.edu@snowball ~]$ gcc ptr.o -o ptr [mweeks@gsuad.gsu.edu@snowball ~]$ ./ptr 78 56 34 12 [mweeks@gsuad.gsu.edu@snowball ~]$ echo notice that "PTR" is *not* recgonized in nasm notice that PTR is *not* recgonized in nasm [mweeks@gsuad.gsu.edu@snowball ~]$ cat ptr.c /* Example of ptr in C (see Irvine's ch 4) - Michael Weeks */ #include union myunion { unsigned int myint; char mychar[4]; }; int main (int argc, char *argv[]) { union myunion example; example.myint = 0x12345678; int i; printf("myint is %x\n", example.myint); printf("mychar[0..3] are ", example.myint); for (i=0; i<4; i++) printf("%x ", example.mychar[i]); printf("\n"); return 0; } [mweeks@gsuad.gsu.edu@snowball ~]$ gcc ptr.c -o ptrc [mweeks@gsuad.gsu.edu@snowball ~]$ echo different filename so it does not overwrite the assembly example different filename so it does not overwrite the assembly example [mweeks@gsuad.gsu.edu@snowball ~]$ ./ptrc myint is 12345678 mychar[0..3] are 78 56 34 12 [mweeks@gsuad.gsu.edu@snowball ~]$ exit exit Script done on Wed 28 Feb 2024 04:32:36 PM EST