Page 1 of 1

Assembler help

Posted: Wed Jan 15, 2003 11:48 am
by beyondsociety
I'm currently reviewing assembly language from a book I have and I have sort of a question. This is what I trying to do:

Code: Select all

Summing a list of numbers

The following example shows how register indirect and based addressing modes may be used to access individual elements of an array. We add a list of numbers together and store the result in a variable called sum:

mov bx,offset list  ; Get offset of list
mov ax,0              
mov al,[bx]           ; Get first number
add al,[bx+1]       ; Add second number 
add al,[bx+2]       ; Add third number
add al,[bx+3]       ; Add fourth number 
add al,[bx+4]       ; Add fifth number
mov sum,ax         ; Store the sum

list   db 10h, 20h, 40h, 2h, 5h
sum dw 0
This is source code for MASM. I using NASM and so it doesn't support the "offset" of the list.

What do they mean by the offset of the list? Could someone explain this to me. Is there a way around this problem? Is it even needed?

Thanks for the help in advance!

Re:Assembler help

Posted: Wed Jan 15, 2003 2:24 pm
by Tim
It's not needed when assembling in NASM.

MASM:

Code: Select all

mov eax, var    ; puts value at var into eax
mov eax, offset var    ; puts address of var into eax
NASM:

Code: Select all

mov eax, [var]    ; puts value at var into eax
mov eax, var    ; puts address of var into eax