NASM Forum > Programming with NASM
Accessing pushed value from a label
tysonprogrammer:
I am writing a program in x86 assembly for FreeDOS. I am trying to stick with 16 bit registers so it will work on older hardware.
The program will create a framed box on the screen and I am pushing a structure with the values for the box on the stack to a routine. I would like to know if I can store this stack value in a label. I am currently using si and that works fine but if I can not use si then I have use for other things. I know I can push it onto the stack to save it but if I don't have to the would be great.
I have the following structure defined.
--- Code: ---struc BOX_FRAME
.TopX: resb 1
.TopY: resb 1
.BottomX: resb 1
.BottomY: resb 1
.Color: resb 1
endstruc
--- End code ---
and this label defined in my data section
--- Code: ---section data
window:
istruc BOX_FRAME
at BOX_FRAME.TopX, db 0
at BOX_FRAME.TopY, db 0
at BOX_FRAME.BottomX, db 0
at BOX_FRAME.BottomY, db 0
at BOX_FRAME.Color, db 0
iend
--- End code ---
I am passing this on the stack using this
--- Code: --- mov ax, data
mov ds, ax
mov [window+BOX_FRAME.TopX], byte 4
mov [window+BOX_FRAME.TopY], byte 4
mov [window+BOX_FRAME.BottomX], byte 25
mov [window+BOX_FRAME.BottomY], byte 10
mov [window+BOX_FRAME.Color], byte COLOR_YELLOW
or [window+BOX_FRAME.Color], byte COLOR_BLUE
push window
call drawWindow
--- End code ---
in drawWindow I have this
--- Code: ---drawWindow:
.init:
push bp
mov bp, sp
mov si, word [bp+4]
--- End code ---
I have the following single-line macros defined
--- Code: ---%define x1 byte [si+BOX_FRAME.TopX]
%define y1 byte [si+BOX_FRAME.TopY]
%define x2 byte [si+BOX_FRAME.BottomX]
%define y2 byte [si+BOX_FRAME.BottomY]
%define color byte [si+BOX_FRAME.Color]
--- End code ---
Here is an example of how the single-line macros are used.
--- Code: --- mdraw_corner x1, y1, BORDER_TOPLEFT
--- End code ---
mdraw_corner is a multi-line macro
Using si works just fine but I am wondering if I can use a label instead. if so, how would I use it to address a value in the structure.
For example If I have a label defined
--- Code: ---section bss
.draw_struct resw 1
--- End code ---
I am attaching what it currently looks like when it runs, for your enjoyment and aww.
thanks much,
Tyson
Frank Kotler:
Hi Tyson,
I may very well be confused!
You define a structure. Good.
You define an instance of the structure named "window". Only one, as far as I can see. This may be where I'm confused. You pass "window" to subroutines on the stack, but it's always the same instance of the structure... or I'm confused... You fill in different values in different subroutines, but always the same instance... IF I'm right. So there's no need to pass "window" and thus no need tp use si.
You could make a "local" ("automatic") instance of your structure on the stack...
--- Code: ---mov bp, sp
sub sp, Box_Frame_size
; and make your instance in this space
mov sp, bp ; make it go away
--- End code ---
but that's not what I think I see...
so:
--- Code: ---%define x1 byte [window+BOX_FRAME.TopX]
;etc
--- End code ---
without using si should work... I think...
But you may want to use different instances... or perhaps you do and I'm missing it. Depends on how confused I am. :)
Best,
Frank
tysonprogrammer:
Frank,
Thanks for your reply. Yes I could use the window instance since it is essentially global and maybe that's where I got off track coming for a OOP language. But just for giggles is there a way to use a reference label instead of si? Or is si used for that?
thanks,
Tyson
Frank Kotler:
Sure. Use bx or di.
I don't think that's what you're looking for. I'm not sure what you are looking for.
--- Code: ---foo equ bp + 4
--- End code ---
?
Best,
Frank
fredericopissarra:
You mean something like this?
--- Code: --- bits 16
struc BOX_FRAME
.TopX: resb 1
.TopY: resb 1
.BottomX: resb 1
.BottomY: resb 1
.Color: resb 1
resb 1 ; To make it word sized.
endstruc
struc STK_FRAME
resw 1 ; return address
.wnd: resb BOX_FRAME_size
endstruc
; Yep... using cdecl convention:
;
; push window
; call f
; add esp,4
f:
; Why do you need to use 16 bits alias registers, even in 16 bit code?
; 386 registers and instructions are available!
mov al,[esp + STK_FRAME.wnd + BOX_FRAME.Color]
;...
ret
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version