NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: ThatGuy22 on December 17, 2010, 02:52:13 PM

Title: How do pointers work in nasm?
Post by: ThatGuy22 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?
Title: Re: How do pointers work in nasm?
Post by: cm 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.
Title: Re: How do pointers work in nasm?
Post by: ThatGuy22 on December 17, 2010, 05:27:04 PM
I will take a look at a tutorial or something on assembly pointers.
Title: Re: How do pointers work in nasm?
Post by: ThatGuy22 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'
Title: Re: How do pointers work in nasm?
Post by: Keith Kanios on December 17, 2010, 06:52:26 PM
Please review the difference between bits and bytes.
Title: Re: How do pointers work in nasm?
Post by: ThatGuy22 on December 17, 2010, 10:03:31 PM
Aren't bits within bytes, that make up the numbers?