//----------------------------------------------------------------- // trymoves.s // // This program illustrates the effect upon the upper-half of // a 64-bit register if a value is moved into its lower half. // // to assemble: $ as trymoves.s -o trymoves.o // and to link: $ ld trymoves.o -o trymoves // and execute: $ ./trymoves // // programmer: ALLAN CRUSE // written on: 02 DEC 2008 //----------------------------------------------------------------- .equ sys_EXIT, 1 .equ sys_WRITE, 4 .equ dev_STDOUT, 1 .section .data bigval: .quad 0x0123456789ABCDEF msg: .ascii " bigval=" buf: .ascii "xxxxxxxxxxxxxxxx \n" len: .quad . - msg .section .text _start: .code64 # convert bigval from binary to hex mov bigval, %rax lea buf, %rdi call rax2hex # display the hexadecimal string mov $sys_WRITE, %rax mov $dev_STDOUT, %rbx lea msg, %rcx mov len, %rdx int $0x80 # now examine the effect of a 'mov' to %eax mov bigval, %rax mov $0x87654321, %eax lea buf, %rdi call rax2hex # display the hexadecimal string mov $sys_WRITE, %rax mov $dev_STDOUT, %rbx lea msg, %rcx mov len, %rdx int $0x80 # terminate this program mov $sys_EXIT, %eax mov $0, %ebx int $0x80 rax2hex: # converts the value in register RAX to a hex string at DS:RDI push %rax push %rbx push %rcx push %rdx push %rdi mov $16, %rcx nxnyb: rol $4, %rax mov %al, %bl and $0xF, %rbx mov hex(%rbx), %dl mov %dl, (%rdi) inc %rdi loop nxnyb pop %rdi pop %rdx pop %rcx pop %rbx pop %rax ret hex: .ascii "0123456789ABCDEF" .global _start .end