/***************************************************************************** * * Name: v_dec_orig * * Description: display numbers in decimal * * From Chapter 7 of "Assembly Language Using the Raspberry Pi" by Robert Dunne * Pages: 151 - 168 * * Author: * Date: * *------|-------|----------------|---------------------------------------------- * ******************************************************************************/ .global _start _start: mov r0, #125 // An arbitrary sample decimal value for test bl v_dec // Call subroutine to view dec value in R0 in // ASCI mov r0, #0 // Exit status code mov r7, #1 // service command to terminate program svc 0 // Issue Linux command to terminate program /* Subroutine v_dec will display a 32-bit register in decimal digits r0 : contains number to be displayed if negative (bit 31 = 1), then a minus sign will be output lr : contains return address ALL REGISTER CONTENTS WILL BE PRESERVED */ v_dec: push {r0 - r7} // Save contents of registers r0 through r7 mov r3, r0 // r3 will hold a copy of input word to be // displayed mov r2, #1 // number of characters to display at a time mov r0, #1 // code for standard output mov r7, #4 // Linux service command to write string // If bit 31 is set, then register contains a negative number and "-" should // be output. cmp r3, #0 // determin if minus sign is needed bge absval // if positive number, then display it ldr r1, =msign // address of minus sign in memory svc 0 // service call to write string out to stdout rsb r3, r3, #0 // get absolute value (negative of negative) // for display /* -------|-------|----------------|---------------------------------------------- */