davitp
davitp

Reputation: 125

Two data segments and 386 code in assembly

Well i'm writing a program, that have to print two strings from different data segments in screen. And i have to use 32-bit addresing mode for my program.

.386
assume cs:codeSegment, ds:dataSeg1, es:dataSeg2, ss:stackSeg
; STACK SEGMENT DECLARATION
stackSeg segment  STACK 'stack'
    db 100h dup(?)
stackSeg ends

; DATA SEGMENTS DECLARATION
dataSeg1 segment  'data'
    s1 db 'First$'
    s1_size dd 6
dataSeg1 ends

dataSeg2 segment 'data'
    s2 db 'Second$'
    s2_size dd 7
dataSeg2 ends
; Code segment
codeSegment segment 'code'
start:
    mov ax, dataSeg1
    mov ds, ax
    mov ax, dataSeg2
    mov es, ax
    mov ah, 9

    mov edx, offset s1 ; need string from DS
    int 21h
    mov edx, offset s2 ; need string from ES
    int 21h


    mov ax, 4C00h
    int 21h


codeSegment ends
end start

I can't understand, how to pass string offsets from correct segment. Can anyone explain what i'm doing wrong?

Thanks

Upvotes: 0

Views: 535

Answers (1)

Frank Kotler
Frank Kotler

Reputation: 3119

Insanity! push ds ; save seg1 push es ; get seg2 into ds pop ds ; print string2 pop ds ; get seg1 back There's a BIOS int 10h function - 13h ??? lookitup - that prints a string from es:bp, too. This is why flat memory model was created! What are they teaching you kids these days???

May need to change your assume directive, too...

Upvotes: 0

Related Questions