//----------------------------------------------------------------- // uint2rax.s // // Here we present our assembly language code for converting // a decimal digit-string into the unsigned integer which is // being represented, returning that number in register RAX. // We assume that the address for that digit-string has been // passed to our assembly language function in register RSI. // // to assemble: $ as uint2rax.s -o uint2rax.o // // programmer: ALLAN CRUSE // written on: 08 FEB 2009 //----------------------------------------------------------------- .section .text uint2rax: # # EXPECTS: RSI = address of decimal digit-string # RETURNS: RAX = value represented by the string # push %rbx # save working registers push %rcx push %rdx push %rsi mov $0, %rax # initialize accumulator mov $10, %rbx # decimal-system's radix nxdgt: mov (%rsi), %cl # fetch next character cmp $'0', %cl # char preceeds '0'? jb inval # yes, not a numeral cmp $'9', %cl # char follows '9'? ja inval # yes, not a numeral mul %rbx # ten times prior sum and $0xF, %rcx # convert char to int add %rcx, %rax # add to prior total inc %rsi # advance source index jmp nxdgt # and check another char inval: pop %rsi # recover saved registers pop %rdx pop %rcx pop %rbx ret # return control to caller .global uint2rax .end