Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- prompt_str: .ascii "Input a string of up to 32 chars long: \000"
- result_str: .ascii "Result is: %s\n\000"
- exit_str: .ascii "Exiting...\n\000"
- fmt_str: .asciz "%[^\n]%*c"
- input_str: .ascii
- .text
- .global main
- .extern printf scanf
- main:
- push {ip,lr}
- mov r4,#0
- start:
- ldr r0, =prompt_str
- bl printf
- ldr r0, =fmt_str
- ldr r1, =input_str
- bl scanf
- ldr r0, =input_str
- mov r2,r0
- ldrb r1,[r0,#+1]
- cmp r1,#0
- bne transform
- ldrb r1,[r0]
- cmp r1,#'Q'
- beq exit
- cmp r1,#'q'
- beq exit
- transform:
- mov r3,#0
- loop:
- cmp r3,#32
- strgeb r4,[r0],#1
- bge print
- add r3,r3,#1
- # manipulate each byte of the input string
- ldrb r1,[r0],#1
- # check if string is terminated with \000
- cmp r1,#'0'
- blt loop
- cmp r1,#'4'
- # if number ['0'-'4'] then add 5
- addle r1,r1,#5
- ble change
- cmp r1,#'9'
- # if number ['5'-'9'] then subtract 5
- suble r1,r1,#5
- ble change
- cmp r1,#'A'
- blt loop
- cmp r1,#'Z'
- # convert to lowercase
- suble r1,r1,#('A' - 'a')
- ble change
- cmp r1,#'a'
- blt loop
- cmp r1,#'z'
- # convert to uppercase
- suble r1,r1,#('a' - 'A')
- change:
- # store transformed byte
- strb r1,[r0,#-1]
- b loop
- print:
- mov r0,r2
- ldr r0, =result_str
- ldr r1, =input_str
- bl printf
- b start
- exit:
- ldr r0,=exit_str
- bl printf
- pop {ip,pc}
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement