Advertisement
Eternoseeker

ass 2 String Length

Mar 23rd, 2023 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 0.88 KB | Source Code | 0 0
  1. section .data
  2.     msg db 10, 10, "Enter the string: "
  3.     msg_len equ $-msg
  4.     smsg db 10, 10, "The length of the string is: "
  5.     smsg_len equ $-smsg
  6.  
  7. section .bss
  8.     string resb 50
  9.     stringl equ $-string
  10.     count resb 1
  11.         char_ans resb 2
  12.  
  13. %macro Print 2
  14.     mov rax, 1
  15.     mov rdi, 1
  16.     mov rsi, %1
  17.     mov rdx, %2
  18.     syscall
  19. %endmacro
  20.  
  21. %macro Read 2
  22.     mov rax, 0
  23.     mov rdi, 0
  24.         mov rsi, %1
  25.     mov rdx, %2
  26.     syscall
  27. %endmacro
  28.  
  29. %macro Exit 0
  30.     mov rax, 60
  31.     mov rdi, 0
  32.     syscall
  33. %endmacro
  34.  
  35. section .text
  36.     global _start
  37. _start:
  38.     Print msg, msg_len
  39.     Read string, stringl
  40.     mov [count], rax
  41.  
  42.     Print smsg, smsg_len
  43.     mov rax, [count]
  44.     call Display
  45.         Exit
  46.  
  47. Display:
  48.     mov rbx, 10
  49.     mov rcx, 2
  50.     mov rsi, char_ans + 1
  51.  
  52. cnt:
  53.     mov rdx, 0
  54.     div rbx
  55.  
  56.     cmp dl, 09h
  57.     jbe add30
  58.     add dl, 07h
  59.  
  60. add30:
  61.     add dl, 30h
  62.     mov [rsi], dl
  63.     dec rsi
  64.  
  65.     dec rcx
  66.     jnz cnt
  67.  
  68.     Print char_ans, 2
  69. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement