/* * Source name : ex2_asmprog.s * Executable name : ex2_asmprog * Author : Jason Fritts * Description : Converts ASCII number to its numeric value * * Build using these commands: * as --gstabs ex1_asmprog.s -o ex1_asmprog.o * gcc -g ex1_asmprog.o -o ex1_asmprog */ .equiv MIN_ASCII, 0x30 .equiv MAX_ASCII, 0x39 .text .global main // program entry point main: push {lr} // Create stack frame push {r5} // Save register r5 // start program code // first zero-out registers mov r0, #0 // put an ASCII character value in %al ldr r5, =num ldrb r5, [r5] // check if character is less than ASCII value for number 0 cmp r5, #MIN_ASCII blo not_a_number // check if character is greater than ASCII value for number 9 cmp r5, #MAX_ASCII bhi not_a_number // if a number, compute the integer number equivalent in r0 sub r0, r5, #MIN_ASCII b end // if not a number, put -1 in r0 not_a_number: mov r0, #-1 // run 'echo $?' after execution to see value end: // end program code pop {r5} // Restore register r5 pop {pc} // Exit & return control to OS .section .rodata // read-only (e.g. string) data .section .data // initialized data num: .byte 0x36 .section .bss // uninitialized data