Advertisement
Guest User

Untitled

a guest
Dec 27th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.76 KB | None | 0 0
  1. .data
  2.         prompt_str: .ascii "Input a string of up to 32 chars long: \000"
  3.         result_str: .ascii "Result is: %s\n\000"
  4.         exit_str: .ascii "Exiting...\n\000"
  5.         fmt_str: .asciz "%[^\n]%*c"
  6.         input_str: .ascii
  7.  
  8. .text
  9. .global main
  10. .extern printf scanf
  11.  
  12. main:
  13.         push {ip,lr}
  14.         mov r4,#0
  15. start:
  16.         ldr r0, =prompt_str
  17.         bl printf
  18.  
  19.         ldr r0, =fmt_str
  20.         ldr r1, =input_str
  21.         bl scanf
  22.  
  23.         ldr r0, =input_str
  24.         mov r2,r0
  25.  
  26.         ldrb r1,[r0,#+1]
  27.         cmp r1,#0
  28.         bne transform
  29.  
  30.         ldrb r1,[r0]
  31.         cmp r1,#'Q'
  32.         beq exit
  33.         cmp r1,#'q'
  34.         beq exit
  35. transform:
  36.         mov r3,#0
  37. loop:
  38.         cmp r3,#32
  39.         strgeb r4,[r0],#1
  40.         bge print
  41.         add r3,r3,#1
  42.         # manipulate each byte of the input string
  43.         ldrb r1,[r0],#1
  44.         # check if string is terminated with \000
  45.  
  46.         cmp r1,#'0'
  47.         blt loop
  48.  
  49.         cmp r1,#'4'
  50.         # if number ['0'-'4'] then add 5
  51.         addle r1,r1,#5
  52.         ble change
  53.  
  54.         cmp r1,#'9'
  55.         # if number ['5'-'9'] then subtract 5
  56.         suble r1,r1,#5
  57.         ble change
  58.  
  59.         cmp r1,#'A'
  60.         blt loop
  61.  
  62.         cmp r1,#'Z'
  63.         # convert to lowercase
  64.         suble r1,r1,#('A' - 'a')
  65.         ble change
  66.  
  67.         cmp r1,#'a'
  68.         blt loop
  69.  
  70.         cmp r1,#'z'
  71.         # convert to uppercase
  72.         suble r1,r1,#('a' - 'A')
  73.  
  74. change:
  75.         # store transformed byte
  76.         strb r1,[r0,#-1]
  77.         b loop
  78. print:
  79.         mov r0,r2
  80.         ldr r0, =result_str
  81.         ldr r1, =input_str
  82.         bl printf
  83.         b start
  84.  
  85. exit:
  86.         ldr r0,=exit_str
  87.         bl printf
  88.         pop {ip,pc}
  89.  
  90. .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement