how to get the segments address and print it in hex

Started by umen, August 17, 2005, 05:41:37 PM

Previous topic - Next topic

umen

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

P1

Is this class homework?

Read up on how to 'mov' a segment register to AX.  What you got is wrong.  Check the Op Code reference.

Read up/ Look up How to output register to ascii string.  What you have is not functional.

Read up How to output a string with Function 09h, INT 21.  Hint:  Your missing the terminator character.

Regards,  P1  :8)


umen

well this is not homework or something , its me trying hard to understand masm ....
ok i fixed (i think) but still can't find way to print the segment address in hex ..
i just moved the ds register to the AX register i tryid to print it .. nothing happened .
any way im scanning the internet just to see some simple example but nothing found.
p/s
what is
the Op Code reference.

thanks allot .

P1

Quote from: umen on August 18, 2005, 08:38:44 AM
what is the Op Code reference.
Inside the QEditor of MASM32 under the Help Menu, is the 'OpCodes Help' file.

I suggest you Download the MASM32 package and work your way through the tutorials.  A great reference source is the Art of Assembly by Randall Hyde.  All these are downloads and will help you along the way to getting started.

MASM32 package: http://www.website.masmforum.com/
Art of Assembly by Randall Hyde: http://webster.cs.ucr.edu/

Regards,  P1  :8)

joe

If I understand, You first must convert value in AX to string. I find simple code to do it.
Try to modify this code:

;  Vzorove(?) reseni prikladu z assembleru zadaneho Lukas Valentou

;
;  Prevod zadaneho sestnactkoveho cisla na desitkove
; =================================================================

A       SEGMENT
        ASSUME CS:A,DS:A
        ORG 100H
START:  .286
        MOV AH,9H
        MOV DX,OFFSET UVOD
        INT 21H
        XOR CX,CX
        MOV BX,4096
ZPET:   XOR AH,AH
        INT 16H

        CMP AL,48
         JB ZPET
        CMP AL,102
         JA ZPET
        XOR DL,DL
        CMP AL,58
         JB MEZI1
ZPET1:  CMP AL,96
         JA MEZI2
ZPET2:  CMP DL,0        ; treatment of input
         JZ ZPET

        MOV DL,AL
        MOV AH,2H
        INT 21H
        CMP AL,96
         JA UPRAV
UPRET:  XOR DL,DL
        SUB AL,48
        XOR AH,AH
        MUL BX
        ADD CX,AX
        SHR BX,4
        CMP BX,0
         JNZ ZPET

        MOV AH,9H
        MOV DX,OFFSET RADKA
        INT 21H

        CMP CX,25599
         JA CHYBA               ; bad extent

        MOV AH,9H
        MOV DX,OFFSET HOT
        INT 21H

        MOV AX,CX
        MOV BL,100
        DIV BL
        XOR AH,AH
        MOV BL,10
        DIV BL
        CALL VETSI
        ADD AL,48
        ADD AH,48
        MOV DX,AX
        MOV AH,2
        INT 21H
        MOV DL,DH
        INT 21H
        MOV AX,CX
        MOV BL,100
        DIV BL
        MOV AL,AH
        XOR AH,AH
        MOV BL,10
        DIV BL
        ADD AL,48
        ADD AH,48
        MOV DX,AX
        MOV AH,2
        INT 21H
        MOV DL,DH
        INT 21H
        INT 20H

MEZI1:  MOV DL,1
        JMP ZPET1
MEZI2:  MOV DL,1
        JMP ZPET2
UPRAV:  SUB AL,39
        JMP UPRET
CHYBA:  MOV AH,9H
        MOV DX,OFFSET CHY
        INT 21H
        JMP START
VETSI:  CMP AL,9
         JA VETSI1
ZZZ:    RET
VETSI1: PUSH AX
        XOR AH,AH
        MOV DL,10
        DIV DL
        MOV DL,AL
        XOR AH,AH
        PUSH AX
        ADD DL,48
        MOV AH,2H
        INT 21H
        POP DX
        MOV AL,10
        MUL DL
        MOV DX,AX
        XOR DH,DH
        POP AX
        SUB AL,DL
        JMP ZZZ   
RADKA   DB 13,10,'$'
CHY     DB '  This number exceeds boundary!',13,10,'$'
HOT     DB 'Dec : $'
UVOD   DB 'Input hex. number in range 0000H .. 63FFH : $'

A ENDS
END START

MichaelW

umem,

The first thing you are doing wrong is posting code that will not assemble. If it will not assemble, how could you have tested it?

If by "the address of the segments" you mean the segment address of the segments defined in your code, the only method that will work for all segments is to use the SEG operator. For example:

MOV  AX,SEG DSEG

For your program you could depend on the loader setting CS to the segment address of CSEG and SS to the segment address of SSEG, but the loader always sets DS to the segment address of the Program Segment Prefix (PSP). EXE programs normally contain code to load the segment address of the near data segment into DS, and for your program to use data you must add code to do this.

Also, you need to add code to properly terminate the program.
eschew obfuscation