mahmood
mahmood

Reputation: 24705

emu8086 wrongly use com file

I wrote a simple assembly code which sums up 4 words

STSEG          SEGMENT
               DB      32 DUP (?)
STSEG          ENDS

DTSEG          SEGMENT
DATA_IN        DW      234DH,1DE6H,3BC7H,566AH
               ORG     100H 
SUM            DW      ?
DTSEG          ENDS


CDSEG          SEGMENT
MAIN           PROC    FAR
               ASSUME  CS:CDSEG,SS:STSEG,DS:DTSEG
               MOV     AX,DTSEG
               MOV     DS,AX   ; load data segment to DS

               MOV     CX,04   ; set counter to 4
               MOV     DI,OFFSET DATA_IN
               MOV     BX,00   ; this is the sum initialized to 0
ADD_LP:        ADD     BX,[DI]
               INC     DI
               INC     DI      ; two INC because we are using words
               DEC     CX
               JNZ     ADD_LP
               MOV     SI,OFFSET SUM    ; since org is 100h, SI will be 100H
               MOV     [SI],BX   ; write the value of sum in that location
               MOV     AH,4CH    ; return to DOS
               INT     21H
MAIN           ENDP
CDSEG          ENDS
               END     MAIN

Using the emu8086, I emulated that code. However as you can see in the screen shot below, the registers don't get the correct values.

Important question is, why the name of the program has .com. I didn't specify that. The value of CX is incorrect. CS and DS have the same values. Why?

enter image description here

Upvotes: 4

Views: 950

Answers (1)

rkhb
rkhb

Reputation: 14399

emu8086 doesn't like that ORG 100H inside the data segment. Delete it.

To force an .exe program, add a "#MAKE_EXE#" at the top of the source.

Upvotes: 5

Related Questions