Author Topic: local array storage  (Read 10405 times)

Offline billium

  • Jr. Member
  • *
  • Posts: 8
local array storage
« on: May 08, 2012, 10:02:53 PM »
In the manual it gives an example for local storage:
Code: [Select]
[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?
« Last Edit: May 08, 2012, 11:02:51 PM by Frank Kotler »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: local array storage
« Reply #1 on: May 08, 2012, 11:33:50 PM »
Code: [Select]
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


Offline billium

  • Jr. Member
  • *
  • Posts: 8
Re: local array storage
« Reply #2 on: May 09, 2012, 10:57:59 PM »
Thanks Frank .. that is what I am doing ..
Code: [Select]
;=============== 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
« Last Edit: May 09, 2012, 11:02:40 PM by billium »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: local array storage
« Reply #3 on: May 10, 2012, 02:36:00 AM »
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...
Code: [Select]
%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



Offline billium

  • Jr. Member
  • *
  • Posts: 8
Re: local array storage
« Reply #4 on: May 10, 2012, 06:09:19 PM »
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