Search code examples
assemblyarmarmv7exitstatus

How to return a number larger than 8 bits from main()?


So as far as I can tell, the exit code returned from r0 only uses the lowest 8 bits of this register. How wouuld I return a value higher than 8 bits?

Here is the ARMv7 code:

@ looping.s
@ calculates sum of integers from 1 to 100
.text
.balign 4
.global main
main:
    MOV r1, #0      @ r1 = 0 as sum
    MOV r2, #0      @ r2 = 0 as counter
loop:
    ADD r2, r2, #1  @ counter = counter + 1
    ADD r1, r1, r2  @ sum = sum + counter
    CMP r2, #100    @ counter - 100
    BLT loop        @ if counter < 100 go to start of loop
    MOV r0, r1      @ Store sum in r0
    BX lr           @ Return summation result to OS

Solution

  • The exit status of a process is 8 bits in size. It is not possible to return a larger exit status by normal means. If you want to output a number larger than 255, you could for example print it to stdout (file descriptor 1) with a write system call.