News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

(Nasm) Local Variable Referencing

Started by brodeur235, July 13, 2009, 11:15:39 PM

Previous topic - Next topic

brodeur235

I realize that this is a masm forum and that my question if nasm specific, but the workshop description does indeed say:
Quote
Any assembler programming topic is welcome
Anyways, on to the problem.

The issue is this: every asm procedure that I write basically follows the same format... here's an example with the non-relevant portion of the procedure removed for brevity:

; @param1 (DWORD) x position of char
; @param2 (DWORD) y position of char
; @return (DWORD) char at (x,y)

%define X_POS DWORD [ebp-8]
%define Y_POS DWORD [ebp-4]

k_get_char:

; setup stack frame
push ebp
mov ebp,esp

; create space for local vars
sub esp,0x00000008

; get x position
mov eax,DWORD [ebp+8]
mov X_POS,eax

; get y position
mov eax,DWORD [ebp+12]
mov Y_POS,eax

; clean up stack frame
mov esp,ebp
pop ebp
ret


Now you can see the "issue" is pretty obvious. I don't want to have to say "DWORD [ebp-X]" every time i want to use a local variable. Not only is it more to type, but more importantly, it's not at all descriptive of the data at that location. So, for now my temporary fixhas been using %defines, or EQU i believe is masms equivalent. I don't like doing this because I only need the preprocessor constants Idefine for that one procedure, yet they are now available throughout my entire kernel module (yes it's a kernel). Is there a better, less messy fix for this? Any/all help appreciated,

Brodeur235

dedndave

if you are moving a data value to eax, for example, you should only have to specify dword (or dword ptr in masm) as an override if the data is defined as some other type (.i.e a string of bytes or words, or a qword)
the assembler knows eax is a dword size
if, however, you store or compare and immediate value with a register address, you have to be more specific

mov [edi],30h ;the assembler has no idea if 30h is a byte, word, dword, etc
so
mov byte ptr [edi],30h
or
cmp word ptr [edi],30h

disintx

http://www.nasm.us/doc/nasmdoc4.html#section-4.8.3

Think this is what you are looking for.

Edit for clarity:
From what I understand is you want descriptive local variables, yes? Then that is the part of the manual for you :)
Maybe I misread..hope it helps anyways.

hutch--

It sounds like having a good look through the NASM manual for the pre-processor directives so that you can use a symbol of your own choice to replace the DWORD [reg+?].

In MASM its something like,


arg1 equ [esp+4]


I would look for a way in the NASM manual to do the same thing and if I remember correctly the NASM pre-processor is easily powerful enough if you are used to it. You want a logic something like this.


MyArg = "DWORD [esp+4]"
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

brodeur235

Quote
From what I understand is you want descriptive local variables, yes?
yes.

Quote
http://www.nasm.us/doc/nasmdoc4.html#section-4.8.3
Good, thanks.

Brodeur235