NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: billium on May 08, 2012, 10:02:53 PM
-
In the manual it gives an example for local storage:
[silly_swap:
%push mycontext ; save the current context
%stacksize small ; tell NASM to use bp
%assign %$localsize 0 ; see text for explanation
%local old_ax:word, old_dx:word
enter %$localsize,0 ; see text for explanation
mov [old_ax],ax ; swap ax & bx
mov [old_dx],dx ; and swap dx & cx
mov ax,bx
mov dx,cx
mov bx,[old_ax]
mov cx,[old_dx]
leave ; restore old bp
ret ;
%pop ; restore original context
I would like to store an string of bytes or array, but I cannot work out how to set the address to a local array. This is for 16 bit code (V40 processor). I am modifying old code so do not have access to global memory or heaps etc.
Any help?
-
lea bx, [old_ax]
... will get ya the address of a local variable. I'm not sure how you declare a local array of a given size in this system, though. Lemmee look into it...
Best,
Frank
-
Thanks Frank .. that is what I am doing ..
;=============== S U B R O U T I N E =======================================
i33ptst:
push bp
mov bp, sp ; stack frame
sub sp, 32 ; 32 bytes variable stacksize
push dx
mov si, 24Dh
lea di, [bp-32]
.rept: ; repeat
lodsb ; get command line param
mov [ss:di], al ; *dispbfr++ = param
inc di
cmp al, 13 ; until param = \r
jnz .rept
xor al, al ; zero string
mov [ss:di],al
lea di, [bp-32]
xor dx,dx
.whdsp: ; while *dispbfr++ != \r
mov al, [ss:di]
cmp al,13
jz .ewdsp
inc di
mov ah, 9
int 3eh ; display *dispbfr
jmp short .whdsp
.ewdsp:
pop dx
mov sp, bp ; restore stack
pop bp
retn
i33ptstend:
I just wanted to use nasm syntax!
Billy
-
Parameters to "%local" are not well documented, but apparently the "usual" size specifiers are supported - byte, word, dword, qword, tword, oword, and yword. Looks like "%localsize" is rounded to "%stacksize" before it's used (so you could use "byte"). Since you want 32 bytes...
%local mystring:yword
would probably work. You might be able to use a macro to define an arbitrary sized array? I think you're better off the way you're doing it.
I've never seen that "int 3Eh". Does that work as intended? RBIL suggests that it needs a command byte and a "nop" after it (?)...
In any case, I think you've got the local array/string and its address right. (untested)
Best,
Frank
-
Thanks for your time Frank .. you are a great person :D .
This is not standard eqpt, V40 processor on a propriety board (from late 80s). I am modifying the firmware to avoid obsolescence!
My method works fine, and I am impressed I was able to disassemble with IDA and re-assemble with Nasm. :)
Many thanks again.
Billy