Home > database >  Omitting the code segment directive in 8086 assembly? (emu8086)
Omitting the code segment directive in 8086 assembly? (emu8086)

Time:08-18

In 8086 assembly program, the segments are declared with special directives like .MODEL, .STACK, etc.

I have noticed that if I omit the .CODE segment directive in emu8086, the program still runs fine. Is there anything wrong with it?

.MODEL SMALL 
.STACK 100H 
.DATA 

;data definitions go here 

; .CODE --> The program works even after omitting this line 

MAIN PROC 
;instructions go here 
MAIN ENDP

;other procedures go here 

END MAIN

CodePudding user response:

Normally with .MODEL SMALL, both the .CODE and .DATA sections could each occupy 64KB (non overlapping). If you didn't tag the .CODE section, emu8086 probably just inserted the code in the .DATA section. This would not harm (too much) because the END MAIN directive clearly says where the program's execution has to begin. It could however limit the amount of code and data together to a single 64KB.

Is there anything wrong with it?

It is a well-known fact that emu8086 has many problems, so not complaining about a missing .CODE tag could be just another example of those problems.


Other than omitting .CODE, you can simplify program development even further by writing .COM programs. Just mention ORG 256 and write code followed by data (up to 64KB with the stack situated at the high end). It could be that easy.

ORG 256

mov dx, OFFSET msg
mov ah, 09h
int 21h
mov ax, 4C00h
int 21h

msg db 'This is a .COM file', 13, 10, '$'
  • Related