//---------------------------------------------------------------- // app64.s // // This example illustrates assembly language programming // for Intel's Extended Memory 64-bit Technology (EM64T). // (It was executed on the CS Department's 'nexus' server // running Fedora Core 4 edition of Linux kernel 2.6.15.) // // assemble using: $ as app64.s -o app64.o // and link using: $ ld app64.o -o app64 // // programmer: ALLAN CRUSE // written on: 20 FEB 2006 //---------------------------------------------------------------- .section .data hex: .ascii "0123456789ABCDEF" # array of hex numerals x: .quad 0x123456789ABCDEF # 64-bit numeric value msg: .ascii "\n x=" # message string buf: .ascii "xxxxxxxxxxxxxxxx \n\n" len: .int . - msg # lessage length .section .text rax2hex: # # This procedure converts the quadword found in register RAX # into its representation as a string of hex numerals at the # address found in register RDI. (Registers are preserved.) # push %rax # preserve CPU registers push %rbx push %rcx push %rdx push %rdi mov %rax, %rdx # copy value into RDX lea hex, %rbx # point RBX to array mov $16, %rcx # nybbles-per-quadword nxnyb: rol $4, %rdx # next nybble into DL mov %dl, %al # copy nybble to AL and $0xF, %al # isolate the nybble xlat # translate to numeral movb %al, (%rdi) # store char to string inc %rdi # then advance address loop nxnyb # and do another nybble pop %rdi # recover saved registers pop %rdx pop %rcx pop %rbx pop %rax ret # return to the caller _start: # convert the 64-bit number x to a hexadecimal string mov x, %rax # load quadword into RAX lea buf, %rdi # point to string buffer call rax2hex # convert RAX to string # display the resulting message mov $4, %rax # service-code for 'write' mov $1, %rbx # specify device-file ID mov $msg, %rcx # load message's address mov len, %rdx # specify message length int $0x80 # request kernel service # terminate this application mov $1, %rax # service-code for 'exit' mov $0, %rbx # specify exit-code value int $0x80 # request kernel service .global _start # make entry-point visible .end # nothing more to assemble