Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .global main
- main: @start of program
- ldr r0, =welcome
- bl printf
- b prompt
- prompt: @prints message that asks user to input a number (1-5)
- ldr r0, =decisionstring
- bl printf
- ldr r0, =intInputPattern
- ldr r1, =decisionNum
- bl scanf
- ldr r2, =decisionNum
- ldr r5, [r2]
- push {r5} @pushes decision integer onto stack
- b decision
- decision: @subroutine that inputs numbers and branches to AND, ORR, EOR, or BIC based on user input
- pop {r10} @pops decision integer off of stack
- mov r1, r10
- ldr r0, =InputNumbers
- bl printf
- cmp r10, #1
- bleq inputHexNums
- temp5:bleq bitwiseAND
- cmp r10, #2
- bleq inputHexNums
- bleq bitwiseORR
- cmp r10, #3
- bleq inputHexNums
- bleq bitwiseEOR
- cmp r10, #4
- bleq inputHexNums
- bleq bitwiseBIC
- cmp r10, #5
- beq exit
- b prompt @else, exit
- errorSubroutine:
- ldr r0, =error
- bl printf
- b inputNumber
- inputNumber:
- push {lr}
- ldr r0, =hexInputPattern
- ldr r1, =hexNum1
- bl scanf
- ldr r2, =hexNum1
- ldr r1, [r2]
- cmp r1, #0
- beq errorSubroutine
- pop {lr}
- push {r1}
- mov r7, #1
- cmp r7, #1
- mov pc, lr
- inputHexNums: @subroutine that inputs two hex numbers
- push {lr}
- bl inputNumber
- pop {r5}
- bl inputNumber
- pop {r6}
- pop {lr}
- temp1:push {r5}
- temp2:push {r6}
- mov pc, lr
- bitwiseAND: @AND subroutine
- temp3:pop {r11}
- temp4:pop {r10}
- AND r12, r10, r11
- push {lr}
- ldr r0, =printnumber
- mov r1, r12
- bl printf
- pop {lr}
- mov pc, lr
- bitwiseORR: @ORR subroutine
- pop {r11}
- pop {r10}
- ORR r12, r10, r11
- push {lr}
- ldr r0, =printnumber
- mov r1, r12
- bl printf
- pop {lr}
- mov pc, lr
- bitwiseEOR: @EOR subroutine
- pop {r11}
- pop {r10}
- EOR r12, r10, r11
- push {lr}
- ldr r0, =printnumber
- mov r1, r12
- bl printf
- pop {lr}
- mov pc, lr
- bitwiseBIC: @BIC subroutine
- pop {r11}
- pop {r10}
- BIC r12, r10, r11
- push {lr}
- ldr r0, =printnumber
- mov r1, r12
- bl printf
- pop {lr}
- mov pc, lr
- exit: @subroutine to exit program
- mov r7, #0x01
- SVC 0
- .data
- .balign 4
- hexInputPattern: .asciz "%x"
- .balign 4
- hexNum1: .word 0
- .balign 4
- hexNum2: .word 0
- .balign 4
- intInputPattern: .asciz "%d"
- .balign 4
- decisionNum: .word 0
- .balign 4
- InputNumbers: .asciz "Now input two hex numbers\n"
- .balign 4
- printnumber: .asciz "%x\n"
- .balign 4
- decisionstring: .asciz "Enter (1) for AND, (2) for ORR, (3) for EOR, (4) for BIC, and (5) to exit\n"
- .balign 4
- andstring: .asciz "You branched to AND\n"
- .balign 4
- orrstring: .asciz "You branched to ORR\n"
- .balign 4
- welcome: .asciz "Welcome to my binary calculator. This program can do 4 operations: AND, ORR, EOR, and BIC\n"
- .balign 4
- error: .asciz "Invalid input.. please input 2 new hex numbers\n"
- .global scanf
- .global printf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement