flat assembler
Message board for the users of flat assembler.
Index
> Main > Address of a Label ... |
Author |
|
revolution 09 Nov 2005, 07:20
Code: label1: some code here mov eax, label1 ;get address of label1 mov eax, [label1] ;get contents of address of label1 |
|||
09 Nov 2005, 07:20 |
|
Matrix 09 Nov 2005, 09:44
i recently made some advanced menu functions that contain the data in an array type, is that what you mean?
Code: mov si, arraytype01 call menu ... ret arraytype01: db "Proc1" dw proc1_addr db 0 db " proc2" dw proc2_addr dw 0 |
|||
09 Nov 2005, 09:44 |
|
vid 09 Nov 2005, 09:47
term "address of label" isn't very good. It's problem coming from stupid MASM syntax. In FASM (and it's also logical too) label is "placeholder for address", so if label "a" is "at address 401122h", then writing "a" should mean same thing as writing "401122h". so
Code: mov eax,a ;mov eax, 401122h mov eax,[a] ;mov eax [401122h] b = 3*a + 5 ;b = 3*401122h + 5 PS: Internally it's a little bit more complicated because of some special cases... |
|||
09 Nov 2005, 09:47 |
|
james 09 Nov 2005, 20:43
Thankyou all for the replies. However,
Matrix, your example is good but I need the address represented by a label not the address of a function. Vid, given your description of using label 'a' like the following: Code: a: ; mov eax, a ; eax now has address of where 'a' is. then defining data like below would also work ? Code: addressOfALabel dw a Yes ? Rgs, James. |
|||
09 Nov 2005, 20:43 |
|
vid 09 Nov 2005, 20:46
yes, right
|
|||
09 Nov 2005, 20:46 |
|
james 09 Nov 2005, 20:54
Vid,
When I try to define storage like this: Code: section '.data' data readable writeable
labelTest dw labelHere
I get the following error: Code: labelTest dw labelHere error: invalid use of symbol. flat assembler version 1.64 3 passes, 1536 bytes. Can you please provide an example of defining a variable that contains the address of where a label is ? Rgs, James ps - thanks for the super quick responses. |
|||
09 Nov 2005, 20:54 |
|
revolution 10 Nov 2005, 00:49
Code: section '.data' data readable writeable labelTest dd labelHere ;<-- use DD for 32 bit addresses |
|||
10 Nov 2005, 00:49 |
|
Matrix 10 Nov 2005, 01:02
james wrote: Thankyou all for the replies. However, James, and the answer to the thread question is yes. i managed this structure a few months before, but its a work to index those labels, it is better i think to make a structure, though fairly more advanced. i think you did not understand what i was trying to write, a label has an address and a function has an address also, i have program in progress that writes the function addresses in memory during run time, depends on far call table, near call table is used, it is possible ok i send code: more will be downloadable soon at my web site - at assemmbly section (free) Code: macro settextcolor _reg,_rf,_gf,_bf,_lf,_rb,_gb,_bb,_lb ; byte register fore:RGBL Back:RGBL { light=1000b red=100b green=10b blue=1 back=(_lb shl 3)+(_rb shl 2)+(_gb shl 1)+(_bb) fore=(_lf shl 3)+(_rf shl 2)+(_gf shl 1)+(_bf) _color=fore+(back shl 4) ;wordcolor=color shl 8 ;dwordcolor=(wordcolor shl 16) or wordcolor mov _reg,_color and $ff} macro dbtextcolor _rf,_gf,_bf,_lf,_rb,_gb,_bb,_lb ; byte register fore:RGBL Back:RGBL { light=1000b red=100b green=10b blue=1 back=(_lb shl 3)+(_rb shl 2)+(_gb shl 1)+(_bb) fore=(_lf shl 3)+(_rf shl 2)+(_gf shl 1)+(_bf) _color=fore+(back shl 4) ;wordcolor=color shl 8 ;dwordcolor=(wordcolor shl 16) or wordcolor db _color and $ff} macro bdisplay _stringpointer001 { mov si, _stringpointer001 call bwritestring } k_up= $48e0 k_down=$50e0 k_esc= $011b k_enter=$1c0d menuxypos=$0505 org 256 mov ax,$03 int 10h mov bx,MainMenuDataBlockPointer call DrawZMenu01 int 20h ; exit DrawZMenu01: ; draw menu from zmenu01 structure from ds:bx push es push $b800 pop es mainloop: and ebx,$ffff .resetdrawmenu: mov si,[bx] ;data start xor edx,edx ;current element or word [bx+7],0 ; cached proc address jz exit_proc.notread ;.readthekey: call breadkey ;returns: AH = BIOS scan code AL = ASCII character note: enhanced cmp ax,k_enter jne .not_enter pop es pusha call word [bx+7] ; cached proc address popa push es push $b800 pop es and word [bx+7],0 ; cached proc address jmp mainloop.resetdrawmenu .not_enter: and word [bx+7],0 ; cached proc address cmp ax,k_up jne .not_up or byte [bx+6],0 ; choicepointer jz .notdec dec byte [bx+6] ; choicepointer .notdec: jmp mainloop.resetdrawmenu .not_up: cmp ax,k_down jne .not_down inc byte [bx+6] ; choicepointer jmp mainloop.resetdrawmenu .not_down: cmp ax,k_esc jne mainloop.resetdrawmenu pusha push ax exit_proc: pop ax popa pop es ret .notread: .drawmenu: mov cx,[bx+4] ;cl=normal color, ch=highlight color mov al,byte [bx+6] ;choicepointer cmp al,dl jne .no_highlight rol cx,8 .no_highlight: push ax bx dx mov bx,[bx+2] add bh,dl call writestring80x25 ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string ! jmp .dontskip .skipelement: .loop:lodsb or al,al jnz .loop .dontskip: pop dx bx ax cmp dl,al jne .notselected lodsw ; proc address in ax mov [bx+7],ax jmp .selected .notselected: lodsw ; proc address in ax .selected: inc dx or byte [si],0 ; last element jnz .notoveryet dec dl cmp [bx+6],dl jnae .ok mov [bx+6],dl .ok: jmp mainloop.resetdrawmenu;.readthekey .notoveryet: jmp exit_proc.drawmenu MainMenuDataBlockPointer: dw .begindatatablock .menuxypos: db 24,7 ; from top left, x,y ; +2 (word) .normalattr: dbtextcolor 1,1,1,0,0,1,0,0 ; byte register fore:RGBL Back:RGBL ; +4 (word) .highlight: dbtextcolor 0,1,0,0,0,0,0,0 ; byte register fore:RGBL Back:RGBL .choicepointer: db 0 ; choicepointer ; +6 (byte) .selectedprocaddress: dw 0 ; proc address offset ; +7 (word) .begindatatablock: db 'Erase & Program, then Lock',0 dw erase_program_lock db 'Erase & Program Only',0 dw erase_program db 'Program',0 dw program db 'Chip Erase',0 dw chiperase db 'Lock',0 dw _lock db 'Communication Speed Test',0 dw spdtest db 'EXIT',0 dw exit_proc db 0 breadkey: ;returns: AH = BIOS scan code AL = ASCII character note: enhanced mov ah,$10 int $16 ret bgotoxy: ; dl=x, dh=y ( 0,0 = upper left ) RETURNS: AX,BX,DX = undefined. push ax dx ; transparency mov ah,2 xor bh,bh int 10h pop dx ax ret bwritestring: ; Writes a 0 terminated string to screen ( string is at ds:si ) push ax bx mov bx,7 ; use video page 0, normal white mov ah,$e .localloop:lodsb or al,al jnz .next_char pop bx ax ret .next_char:int 10h jmp .localloop writestring80x25: ; DS:SI = address of string bl=x bh=y ch=color , 0 terminated string ! xor ax,ax xchg al,bh mov di,ax shl di,2 add di,ax shl di,4 add di,bx shl di,1 .again: mov ah,ch lodsb or al,al jz .ext2 stosw jmp .again .ext2: ret highlightbackground: ; eax = dword color xor di,di mov cx,1000 .setback: and dword [es:di],$00ff00ff or dword [es:di],eax add di,4 loop .setback ret bwritedword: ; EAX = number, BL = base push eax ebx ecx edx and ebx,$ff cmp bl,2 ; base can't be less than 2 jge .start mov bl,10 ; using bx = 10 instead .start: xor ecx,ecx ; cx = 0 .new: xor edx,edx ; dx = 0 div ebx ; number / base push dx ; push the remainder inc ecx ; increase the "digit-count" or eax,eax ; if the quotient still is not 0, do it once more jnz .new .loop: pop ax ; pop the remainder cmp al,10 sbb al,69h das mov ah,$e int 10h loop .loop pop edx ecx ebx eax ret cls80x25t: ; clear the text screen really fast xor eax,eax mov di,ax mov eax,$07200720 mov cx,1000 rep stosd ret spdtest: call display_currentproc ret _lock: call display_currentproc ret chiperase: call display_currentproc ret program: call display_currentproc ret erase_program: call display_currentproc ret erase_program_lock: call display_currentproc ret display_currentproc: movzx eax,byte [bx+6] mov bl,10 call bwritedword ; EAX = number, BL = base ret |
|||
10 Nov 2005, 01:02 |
|
vid 10 Nov 2005, 01:42
james: apps in win32 are usually (well, always) loaded above 10000h, so it won't fit in dword. sorry, i missed that. it's little like if you was trying to compile "something dw 401A2Bh", it can't fit. Labels are 32bit so use DD as revolution said. Another problem is that in win32 they aren't really constant, so you can't sometimes use them in that manner, but for now better don't care about that oo much.
|
|||
10 Nov 2005, 01:42 |
|
james 10 Nov 2005, 01:46
Oh boy !!
I can't believe I used DW instead of DD. Im feeling very stupid right now as I do know better. Changing to the right size worked. Thanks for your patience. Rgs, James. |
|||
10 Nov 2005, 01:46 |
|
vid 10 Nov 2005, 02:00
we were all starting.... (but we didn't have internet)
|
|||
10 Nov 2005, 02:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.