Author Topic: How do pointers work in nasm?  (Read 15756 times)

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
How do pointers work in nasm?
« on: December 17, 2010, 02:52:13 PM »
How would I use pointers in nasm, I tried this which seems like it should work but it doesn't:
Code: [Select]
       mov bl, PointTo  ;Make bl point to the variable PointTo
mov ah, 0x0e     ;DOS function to print character.
mov al, [bl]       ;Print character that bl points to ('H')
int 0x10            ;Print character

PointTo:
db 'H'               ;char to print
What would make this code work or what am I doing wrong?
« Last Edit: December 17, 2010, 02:54:34 PM by ThatGuy22 »

Offline cm

  • Jr. Member
  • *
  • Posts: 65
Re: How do pointers work in nasm?
« Reply #1 on: December 17, 2010, 03:55:51 PM »
Read the error message. Then inform yourself about effective addresses somewhere else, and find out why the error message is displayed.
C. Masloch

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
Re: How do pointers work in nasm?
« Reply #2 on: December 17, 2010, 05:27:04 PM »
I will take a look at a tutorial or something on assembly pointers.

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
Re: How do pointers work in nasm?
« Reply #3 on: December 17, 2010, 05:43:03 PM »
Ok, I have found out what I was doing wrong I was storing the address of the pointer in a 8 byte register I needed a 16 byte one - because I was doing this in real mode. I now have a different problem I wrote a program to use the pointer but I will not print out what is in the pointer. I think this is because I stored the Pointer in a 16 byte register and it needs to go to a 8 byte one for the DOS print char function. Here is my code, how do I get the whole value in my pointer into a 8 byte register. I think it is only trasfering half of the value to al in my program from which part of the register I do not know(What is the default part of the register that it transfers?). This is my test program:
Code: [Select]
AppMain:
mov bx, Pointer
mov ah, 0x0e
mov al, [bx]   ;Here is where I don't think it is taking the whole value from bx, so how do I fix this?
int 0x10
jmp AppMain  ; Hang the program with an infinite loop.

Pointer:
db 'H'

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: How do pointers work in nasm?
« Reply #4 on: December 17, 2010, 06:52:26 PM »
Please review the difference between bits and bytes.

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
Re: How do pointers work in nasm?
« Reply #5 on: December 17, 2010, 10:03:31 PM »
Aren't bits within bytes, that make up the numbers?