News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About Segment Registers

Started by Force, March 11, 2012, 02:41:26 PM

Previous topic - Next topic

Force



.model small
.data
str1 db "Force$"
.stack
.code

mov ax,@data
push ax
pop ds


mov al,ds:00h ;Get first byte of data segment
mov dl,al

mov ah,02h
int 21h



mov ah,4ch
int 21h
end 



Hi !..


In this code i get 1 byte from data segment directly

and i tried to get 1 byte from stack segment with same way


I added this code but its failed

mov bl,dl
push bx

mov al,ss:00h
mov dl,al

mov ah,02h

int 21h
pop bx


Is it imposibble or my code is wrong ?
Never Stop Until You Are Better Than The Best

MichaelW

At least in this case, your assumption that str1 is at the beginning of the data segment is wrong.

.model small
.data
str1 db "Force$"
.stack
.code
start:
    mov ax,@data
    push ax
    pop ds

    I=0
    REPEAT 20
    mov dl,ds:I
    mov ah,02h
    int 21h
    mov dl, 13
    mov ah,02h
    int 21h
    mov dl, 10
    mov ah,02h
    int 21h
    I=I+1
    ENDM
   
    mov bx, OFFSET str1
    mov cx, SIZEOF str1
  @@:
    push cx
    mov dl, [bx]
    mov ah,02h
    int 21h
    inc bx
    pop cx
    dec cx
    jnz @B

    mov dl, 13
    mov ah,02h
    int 21h
    mov dl, 10
    mov ah,02h
    int 21h

    xor ah, ah
    int 16h

    mov ah,4ch
    int 21h

end start




!
2
Σ



L

!

F
o
r
c
e
$
K
V
Force$

eschew obfuscation

FORTRANS

Hi,

   You are using the DOS Console Output function to show
the byte from the stack segment.  That is used for character
output.  The stack segment is usually zeroed out and the
character for '00'H is a blank at best.  So you will not see
anything.  Try a hexadecimal output routine.  Or use the
other form of declaring a stack segment.


; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.  Stack segment:
STCKSEG SEGMENT STACK
        DB      48 DUP('STACK!!!')      ; Stack area, and filler (384 Bytes)
STCKSEG ENDS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


   Also useful sometimes when checking for stack usage problems.

   You can make a listing to see if the data is laid out as you
expect as well.

HTH,

Steve N.

Force

My poor side in x86 is segments
i dont have enough knowladge about them so I asked that kind of question

Steve how can i use hex ? can u post a simple code ?
Never Stop Until You Are Better Than The Best

dedndave

the attachment on the following post has a copy of SymDeb and a little example of using it...
http://www.masm32.com/board/index.php?topic=18481.msg156179#msg156179

FORTRANS

Hi,

   Here is a thread were I posted some code to print AL as
hexadecimal.  Or a larger value byte by byte.  There is code
in the thread as well by Dave (dedndave).

http://www.masm32.com/board/index.php?topic=13415.msg106047#msg106047

Cheers,

Steve

Force

Thanks all

hope those examples helps me
Never Stop Until You Are Better Than The Best

locche

Quote from: Force on March 11, 2012, 02:41:26 PM


.model small
.data
str1 db "Force$"
.stack
.code

mov ax,@data
push ax
pop ds


mov al,ds:00h ;Get first byte of data segment
mov dl,al

mov ah,02h
int 21h



mov ah,4ch
int 21h
end 



Hi !..


In this code i get 1 byte from data segment directly

and i tried to get 1 byte from stack segment with same way


I added this code but its failed

mov bl,dl
push bx

mov al,ss:00h
mov dl,al

mov ah,02h

int 21h
pop bx


Is it imposibble or my code is wrong ?


Hiya Force

Sorry to come to the party so late, but if you're still wandering, I have an explanation.  You put BX on the stack, and pushed it on TOP .  Then you read a byte from the BOTTOM of the stack. You just need to read and write from the same location of a given segment
and you'll be fine.
Here's an example.

DATA SEGMENT
DB 'FORCE',24H
DATA ENDS
STACK SEGMENT STACK 'STACK'
   DB  64 DUP('IMASTACK')                  ;; it does help me to see if I wrote to ss or not, if 'F' prints, I did
STACK ENDS
CODE SEGMENT
  ASSUME CS:CODE, DS:DAT, SS:STACK
MAIN PROC FAR
    PUSH DS
    SUB AX,AX
    PUSH AX
    MOV AX,DATA
    MOV DS,AX
   
   
    MOV BL, BYTE PTR DS:0       ;;   fetch first byte from ds
    MOV SS:0, BL                      ;;   write it to first byte of ss for later
    PUSH BX                             ;; push onto stack like you done
    MOV BP,SP                          ;;  fetch its index
    MOV DL, BYTE PTR [BP]        ;; copy and print
   
    MOV AH,02
    INT 21H

    MOV DL, BYTE PTR SS:0           ;; now copy and print your first byte from stack
    INT 21H

    RET
MAIN ENDP
CODE ENDS
END MAIN
   

   

   
   
   

dedndave

Quote from: Force on March 11, 2012, 02:41:26 PM
I added this code but its failed

mov bl,dl
push bx

mov al,ss:00h
mov dl,al

mov ah,02h

int 21h
pop bx


Is it imposibble or my code is wrong ?


first, this is invalid coding
mov al,ss:00h
what you may have meant was
mov al,ss:[00h]

but - SS:[0] does not point to the item that was just pushed
it points to what is tradionally called the "bottom" of the stack
it is unlikely and undesirable that you would ever place anything at that location with PUSH

        push    bp
        push    dx         ;the contents of DL is what you are interested in
        mov     bp,sp      ;in 16-bit, you cannot use SP to address stack data directly
        mov     dl,[bp]    ;you should use BP (notice that DL will not change, here)
        mov     ah,2
        int     21h
        pop     bx         ;you wanted it in BX, i guess
        pop     bp

Force

Sorry for late replying...
I was far from forum for 1 month .. I just noticed last posts

Thanks for helping Locche  and Dave   :U
Never Stop Until You Are Better Than The Best