displayNumber1.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. WORD HEXADECIMAL to ASCII conversion
  2. section .data
  3. message db "Stored value in array : " ;simple message declartion
  4. length equ $-message ; this statement stores value of length of message
  5. nl db "",10
  6. nll equ $-nl
  7. reference_table : db "0123456789ABCDEF" ;reference table is needed for XLAT instruction
  8. array : dw 0xFACD,0x0E12,0x5432 ;This is the array we wish to print
  9. ;=======================================================================
  10. section .bss
  11. converted_value resw 1 ;this will store the ASCII content of array
  12. counter resb 1 ;this will store numbers to be converted
  13. counter_word resb 1 ;to specify that we are converting a word
  14. %macro PRINT 2 ;macro decalration for print vaule on screen
  15. mov rax,1
  16. mov rdi,1
  17. mov rsi,%1
  18. mov rdx,%2
  19. syscall
  20. %endmacro
  21. ;=======================================================================
  22. section .text
  23. global _start
  24. _start:
  25. PRINT message,length ;Print the message
  26. mov byte[counter],3 ;initialize counter (number of words to print)
  27. mov r8,array ;Give the source address by storing in RSI register
  28. loop_number:
  29. mov byte[counter_word],2 ;as word contains 2 bytes (for double word 4 bytes)
  30. ;this loop is for word conversion
  31. loop_word:
  32. rol word[r8],8 ;To take values from MSB to LSB
  33. mov r9,converted_value ;Give the Destination address by storing in RDI register
  34. CALL HEX_ASCII ;Call the conversion Routine
  35. PRINT converted_value,2
  36. dec byte[counter_word]
  37. jnz loop_word
  38. PRINT nl,nll
  39. add r8,2 ;point to next word to convert
  40. dec byte[counter]
  41. jnz loop_number
  42. ;=======================================================================
  43. ;exit ;EXITING the program
  44. mov rax,60
  45. mov rbx,0
  46. syscall
  47. ;=======================================================================
  48. HEX_ASCII:
  49. mov al,byte[r8] ;Get the byte content pointed by RSI
  50. mov ah,al ;Make another copy of same byte
  51. shr al,4 ;Shift by 4 bits to right to get the MSB
  52. mov ebx,reference_table ;This is necessary for XLAT to work
  53. XLAT ;This will perform conversion
  54. mov byte[r9],al ;Move the result(ASCII of MSB) in Destination
  55. inc r9 ;Point to next byte of destination
  56. mov al,ah ;Retrive the copy of byte to be converted
  57. and al,0Fh ;Mask the MSB (We consider only LSB nibble now)
  58. mov ebx,reference_table ;This is necessary for XLAT to work
  59. XLAT ;This will perform conversion
  60. mov byte[r9],al ;Move the result(ASCII of LSB) in Destination
  61. RET