I wrote a simple assembler code that sums 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 emu8086
, I emulated this code. However, as you can see in the screenshot below, the registers are not getting the correct values.
An important question is why the program name has .com
. I did not specify this. CX value is incorrect. CS and DS have the same meaning. Why?

source
share