flat assembler
Message board for the users of flat assembler.

Index > DOS > how to get the segments address and print it in hex?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
umen



Joined: 14 Aug 2005
Posts: 16
umen 17 Aug 2005, 15:23
Hello im trying to make simple code that will print me the address of the segments :
for example i like to print the data segment address ( in hex)

DSEG SEGMENT
DSEG ENDS
SSEG SEGMENT STACK
DW 100H DUP(?)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG
BEGIN:
MOV AX, OFFSET DS ;
MOV BX,AX
MOV AH,9
INT 21H
CSEG ENDS
END BEGIN


but unfortunately nothing is printed on the screen ... what im doing wrong here?


Tnx for the hellpers
Post 17 Aug 2005, 15:23
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 17 Aug 2005, 17:35
btw you should read the documentations of fasm , it is not tasm.
hm,
since int 21h ah 9 prints ascii value , you have to convert the byte value to ascii numbers first, one byte can be represented in hexadecimal base with 2 hexadecimal numbers

simple code to dump registers on screen.

Code:
org $100 ;program starting location 100h

;mov esp,$FABC

push esi edx ecx ebx eax ; put registers on stack
mov si,axeq ; display variable offset
call bwritestring ; put variable at offset si on screen
mov ebx,16 ; hexadecimal display of value
pop eax ; load eax from stack
call putlongint ; display value in eax
call bendline   ; end the line

mov si,bxeq
call bwritestring
pop eax
call putlongint
call bendline

mov si,cxeq
call bwritestring
pop eax
call putlongint
call bendline

mov si,dxeq
call bwritestring
pop eax
call putlongint
call bendline

mov si,cseq
call bwritestring
mov ax,cs
call putlongint
call bendline

mov si,dseq
call bwritestring
mov ax,ds
call putlongint
call bendline

mov si,eseq
call bwritestring
mov ax,es
call putlongint
call bendline

mov si,fseq
call bwritestring
mov ax,fs
call putlongint
call bendline

mov si,gseq
call bwritestring
mov ax,gs
call putlongint
call bendline

mov si,sieq
call bwritestring
pop eax
call putlongint
call bendline

mov si,dieq
call bwritestring
mov eax,edi
call putlongint
call bendline

mov si,sseq
call bwritestring
mov ax,ss
call putlongint
call bendline

push dword $12345678
;pop eax

mov si,speq
call bwritestring
mov bx,16
mov eax,esp
call putlongint
call bendline

mov si,spdeq
call bwritestring
mov edi,esp
;mov eax,[edi-4] ;- esp-2 cimen sp értéke van
mov eax,[edi]
call putlongint
call bendline

pop eax

mov si,bpeq
call bwritestring
mov eax,ebp
call putlongint
call bendline


cli             ; clear interrupts while we setup a stack
mov ax,0x9000   ; this seems to be the typical place for a stack
mov ss,ax
mov sp,0xffff   ; let's use the whole segment.  Why not?  We can Smile
sti             ; put our interrupts back on


int 20h ; exit function there are alternatives

axeq db 'EAX=$',0 ; variable declarations.- messages to display
bxeq db 'EBX=$',0
cxeq db 'ECX=$',0
dxeq db 'EDX=$',0
cseq db 'CS=$',0
dseq db 'DS=$',0
eseq db 'ES=$',0
fseq db 'FS=$',0
gseq db 'GS=$',0
sieq db 'ESI=$',0
dieq db 'EDI=$',0
sseq db 'SS=$',0
speq db 'ESP=$',0
spdeq db '[ESP]=$',0
bpeq db 'EBP=$',0

bendline: ; ends the line ( adds y loc = 1 x loc = 0 )
push ax bx
mov bx,7 ; returns:  AX = 0xE0A ; BX = 7
mov ax,$E0D
int 10h
mov al,$A
int 10h
pop bx ax
ret

bwritestring: ; Writes a 0 terminated string to screen ( string is at ds:si )
push ax bx si
mov bx,0007h ; use video page 0, normal white
localloop:
lodsb
or al,al
jnz next_char
pop si bx ax
ret
next_char:
mov ah,0eh
int 10h
jmp localloop

putint: ; AX = number, BX = base
  push ax bx cx dx
  cmp bx,2 ; base can't be less than 2 Smile
  jge .start
  mov bx,10     ; using bx = 10 instead
  .start:
  xor cx,cx     ; cx = 0
  .new:
  xor dx,dx     ; dx = 0
  div bx        ; number / base
  push dx       ; push the remainder
  inc cx        ; increase the "digit-count"
  or ax,ax      ; 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
push bx
mov bx,15 ;mov bl,15 ;xor bh,bh
mov ah,$e
int 10h
pop bx
  loop .loop
  pop dx cx bx ax
ret

putlongint: ; EAX = number, EBX = base
  push eax ebx ecx edx
  cmp ebx,2 ; base can't be less than 2 Smile
  jge .start
  mov ebx,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
push bx
mov bx,15 ;mov bl,15 ;xor bh,bh
mov ah,$e
int 10h
pop bx
  loop .loop
  pop edx ecx ebx eax
ret
    


added more comments...


Last edited by Matrix on 18 Aug 2005, 10:15; edited 1 time in total
Post 17 Aug 2005, 17:35
View user's profile Send private message Visit poster's website Reply with quote
umen



Joined: 14 Aug 2005
Posts: 16
umen 17 Aug 2005, 18:29
sorry but i didn't understand any thing.
Post 17 Aug 2005, 18:29
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 18 Aug 2005, 01:57
Read manuals, tutorials, etc. For FASM, because a TASM tutorial does no good with FASM.

Try the TAJGA tutorial, at decard.net.
Post 18 Aug 2005, 01:57
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 18 Aug 2005, 06:24
Quote:
For FASM, because a TASM tutorial does no good with FASM

Well, i disagree here, you should learn to translate TASM into FASM, syntaxes aren't that different. There is to few things in TAJGA tutorial for now (and for too long i quess Sad ).
Try to start with examples that comes with FASM.
Post 18 Aug 2005, 06:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 09:55
hi, umen
you have to understand everything you wrote, difference between F and 'F' etc. here is a working commented example in fasm (maybe not best, just fast) - it shows values of segment registers when program is just started. if need exactly tasm example - maybe i can later (have no tasm installed here to check)


Description:
Download
Filename: umen.1.zip
Filesize: 1.51 KB
Downloaded: 552 Time(s)


_________________
UNICODE forever!
Post 18 Aug 2005, 09:55
View user's profile Send private message Visit poster's website Reply with quote
umen



Joined: 14 Aug 2005
Posts: 16
umen 18 Aug 2005, 11:54
Hello all!
tnx you shoorick for efford
but i just notice that you are talking here about fsam
and i was talking about simple masm....
Post 18 Aug 2005, 11:54
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 18 Aug 2005, 11:57
hm umen,
i think fasm is simple,

you make simple com file like this

Code:
org 100h ; start

; code here

ret ; int 20h ;... exit

; variables
    
Post 18 Aug 2005, 11:57
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 13:05
if you want exactly in masm - here is ready example, but i agree with Matrix about fasm


Description:
Download
Filename: DosExe.zip
Filesize: 1.05 KB
Downloaded: 582 Time(s)


_________________
UNICODE forever!
Post 18 Aug 2005, 13:05
View user's profile Send private message Visit poster's website Reply with quote
umen



Joined: 14 Aug 2005
Posts: 16
umen 18 Aug 2005, 13:38
shoorick again tnx allot , im very thankful for your help
but in the example you gave me you print the string , this is no problem and i know how to do this .
my problem is that i need to print the hex address of the data segment in masm (.data in your example )
i hope i made my self clear
again tnx allot
Post 18 Aug 2005, 13:38
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 13:46
Very Happy got it, wait a little (firstly i'll check if i have 16-bit linker here)
Post 18 Aug 2005, 13:46
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 14:13
no, i have no 16-bit masm linker, so, try this - if it will not help - let us know


Description:
Download
Filename: umen1.1.zip
Filesize: 1.75 KB
Downloaded: 551 Time(s)


_________________
UNICODE forever!
Post 18 Aug 2005, 14:13
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 14:29
downloaded linker - all ok, here exe to test:


Description:
Download
Filename: umen1.zip
Filesize: 423 Bytes
Downloaded: 566 Time(s)


_________________
UNICODE forever!
Post 18 Aug 2005, 14:29
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 18 Aug 2005, 14:55
shorick: are you trying to become top poster here? Smile wish you lot of success Wink
Post 18 Aug 2005, 14:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 18 Aug 2005, 18:12
hmm,
i think i will have to moderate then ;>
btw, you should learn fasm on fasm board...
Post 18 Aug 2005, 18:12
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 18 Aug 2005, 18:46
if any try *asm and will not understand its taste it will never go to fasm. i started from tasm, then tried masm, then fasm. not because somebody restrict, fasm is my choise. don't you see here is newb? he should to compare and make own choice.
Quote:

are you trying to become top poster here?
never Smile those ages when i had ambitions are gone a long time ago - this is just help easy to me Wink

regards!
Post 18 Aug 2005, 18:46
View user's profile Send private message Visit poster's website Reply with quote
umen



Joined: 14 Aug 2005
Posts: 16
umen 18 Aug 2005, 19:48
Thanks allot shoorick!!! you made my day !
tnx allot for your help , im sure u just helped allot of masm newbee's like me
Post 18 Aug 2005, 19:48
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 18 Aug 2005, 19:58
shoorick: sure, i was just joking. thanks for anyone whoever found help in board like this
Post 18 Aug 2005, 19:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 19 Aug 2005, 05:10
i was explaining Wink anyway, here is a sugg: it would be good to have "Newbies" thread at the end of "Main" thread where such topics could be collected, then newbies will easy find where they should start read, and there will be no mess in the main thread. regards!
Post 19 Aug 2005, 05:10
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 19 Aug 2005, 06:12
yup, not a bad idea, special section for general newbies' assembly questions. Or somehow marking the thread that it's for newbies
Post 19 Aug 2005, 06:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.