.global main
.extern printf
.extern scanf
.section .data
prompt: .asciz "Enter an integer between 2 and 100: "
error_msg: .asciz "Invalid input. Exiting.\n"
even_msg: .asciz "The even numbers from 1 to %d are:\n"
odd_msg: .asciz "The odd numbers from 1 to %d are:\n"
sum_even_msg: .asciz "The even sum is: %d\n"
sum_odd_msg: .asciz "The odd sum is: %d\n"
int_format: .asciz "%d\n"
scanf_format: asciz "%d"
.section .bss
input_num: .space 4
.section .text
main:
ldr r0, =prompt
bl printf
ldr r0, =scanf_format
ldr r1, =input_num
bl scanf
ldr r2, =input_num
ldr r3, [r2]
cmp r3, #2
blt invalid_input
cmp r3, #100
bgt invalid_input
ldr r0, =even_msg
ldr r1, [r2]
bl printf
mov r4, #2
mov r5, #0
even_loop:
cmp r4, r3
bgt print_even_sum
ldr r0, =int_format
mov r1, r4
bl printf
add r5, r5, r4
add r4, r4, #2
b even_loop
print_even_sum:
ldr r0, =sum_even_msg
mov r1, r5
bl printf
ldr r0, =odd_msg
ldr r1, [r2]
bl printf
mov r4, #1
mov r5, #0
odd_loop:
cmp r4, r3
bgt print_odd_sum
ldr r0, =int_format
mov r1, r4
bl printf
add r5, r5, r4
add r4, r4, #2
b odd_loop
print_odd_sum:
ldr r0, =sum_odd_msg
mov r1, r5
bl printf
mov r0, #0
b exit
invalid_input:
ldr r0, =error_msg
bl printf
mov r0, #1
b exit
It allows me to input a number, prints the even sum messages with 0 in place of d%, then returns an error. I've already fixed some errors in regards to misassigning my scanf and integer formats, as well as syntax errors regarding printing the integer input. I'm assembling and running the code on a Raspberry Pi, with the C library exported in. I've managed to successfully assemble and link the code, and have tried using gdb, but I'm not super familiar with ARM (or any assembly code), so I'm having issues even seeing where the problem might be.