简体   繁体   中英

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

Insanity! push ds ; save seg1 push es ; get seg2 into ds pop ds ; print string2 pop ds ; get seg1 back 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM