Advertisement
MichaelPetch

array of string pointers

May 22nd, 2021
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. .model small
  2. .stack 256
  3.  
  4. .data
  5. str1 db 'Shirt$'
  6. str2 db 'Pants$'
  7. str3 db 'Socks$'
  8.  
  9. strarray dw offset str1, offset str2, offset str3
  10.  
  11. .code
  12.  
  13. start:
  14. ; Setup the DS register to point at .data
  15. mov ax, @data
  16. mov ds, ax
  17.  
  18. ; TYPE operator returns the size of an element in strarray.
  19. ; 2 in this case since we defined strarray with elements
  20. ; of type word (DW)
  21.  
  22. ; Get the pointer stored in 3rd element of strarray to DX
  23. mov dx, strarray[2*(TYPE strarray)]
  24.  
  25. ; Print the string using DOS function call
  26. mov ah, 9h
  27. int 21h
  28.  
  29. ; ALternatively you can access the array element through
  30. ; a register like BX, SI, DI
  31.  
  32. ; Get the offset of the 2nd element into BX
  33. mov bx, 1*(TYPE strarray)
  34. ; Get the pointer stored in 2nd element of strarray to DX
  35. mov dx, strarray[bx]
  36.  
  37. ; Print the string using DOS function call
  38. mov ah, 9h
  39. int 21h
  40.  
  41. ; Exit program
  42. mov ax, 4C00h
  43. int 21h
  44.  
  45. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement