I'm a beginner at 8086 assembly. I'm learning from an old early 90s book I found in a thrift store. I thought it might be fun to program like it's 1992.
Anyway I'm done with the book and now i've written a few programs at the command prompt on my old Win95 laptop.
I'm having issues with this one not working as intended after switching over to using the 'les' instruction. However it did work when I set up the ES and DI registers with the appropriate address manually.
;************************************
; STACK SEGMENT
;************************************
TheStack SEGMENT STACK ;STACK specifies the stack segment
db 64 dup (THESTACK) ;reserves 512 bytes for the stack
TheStack ENDS
;************************************
; END STACK SEGMENT
;************************************
;************************************
; DATA SEGMENT
;************************************
Data SEGMENT
BufAddr DD 0b8000000h
Data ENDS
;************************************
; END DATA SEGMENT
;************************************
;************************************
; CODE SEGMENT
;************************************
Code SEGMENT
assume CS:Code,DS:Data
MAIN PROC
Start: ;execution begins
;setup input for stosw
les di, DWORD PTR BufAddr
mov cx,0f4fh ;cx contains the number of times stosw will loop
cld
;draw smileys
mov ax,0f01h ;0f is the text attribute for white on black, 01 is the hex code for a smiley
rep stosw ;write it all to the buffer
;EXIT
mov AH,4CH ;Setup the terminate dos process service
mov AL,0 ;ERRORLEVEL takes 0
int 21H ;return to dos
MAIN ENDP
Code ENDS
;************************************
; END CODE SEGMENT
;************************************
END Start ;Start is the Main procedure
Okay, so this program is supposed to draw a bunch of smiley ascii characters in the command prompt window, but it's not working.
It does work when I replace the 'LES' line with the following lines of code.
mov bx,0b800h
mov es,bx
xor di,di
Doesn't the 'LES' instruction when used with the BufAddr variable accomplish the same thing as the previous three lines of code?
When I debug the compiled exe (I'm using MASM 6.11 as the compiler) I notice that the ES and DI registers are not being loaded with the correct values.
mov ax, SEG data
andmov ds, ax
statements at the start of your code. – Scarlattiassume CS:Code,DS:Data
in your assembly file, this does not actually set these segment registers. It gives a hint as to what they are suppose to hold. Since the assembler doesn't generate code to set the data segment up and point it at the segmentData
you are forced to do it yourself. As Ross suggestmov ax, SEG data
mov ds, ax
should work. The reason your code doesn't work is because without properly initializing DS at the start of your program the instructionles di, DWORD PTR BufAddr
will loadBuffAddr
from the wrong memory location. – Evangelizeles di, DWORD PTR BufAddr
is the same asles di, DWORD PTR [DS:BufAddr]
the default segment register for the memory load is DS . If DS is wrong then it will fail to load from the proper memory address, – Evangelizedb 64 dup (THESTACK)
doesn't assemble for me. I'd suggest usingdb 512 dup (?)
instead. – Scarlattidb 64 dup ("THESTACK")
– Unfamiliar