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.
Before loading the segment and offset from RAM, you need to set the DS
register to actually point to your data segment. By default, DS
points to your PSP, which isn't the place you want it to point to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With