NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: codeferever on September 23, 2010, 05:54:14 AM
-
why it doesn't work?
;nasm -fbin -o show.com show.asm
org 100h
mov ax, 0xb800
mov es, ax
mov di, 0
Key_wait:
mov ah, 8
int 21h
mov al,'B'
mov es:[di],al
jmp Key_wait
???
-
I don't know why that wouldn't work - looks okay to me. You might try:
...
mov al, 'B'
mov ah, 7 ; white-on black "attribute" (color)
mov [es:di], ax ; write both character and attribute
...
Hmmm, wait - you've got "es:[di]". Nasm wants the segment inside the "[]"s, too - other assemblers like it outside. Could that be your only problem? I don't think Nasm will assemble that, as posted - "invalid combination of opcode and operands"...
If that doesn't work, there's another possibility - it may be that "fake dos", as provided by certain Windows versions, starts screen memory at some other address than 0B800:0000. There's a "query video information" interrupt that returns the "regeneration buffer" (what I usually call "screen memory") as one of its fields. I'd have to look up how to use it. I don't think you should have to do that... Try just moving the "es:" inside the "[]"s first...
Best,
Frank
-
mov ah, attribute
mov al, byte to display
stosw
The stosw opcode is really what you're missing as you need to be writing the attribute, as well as incrementing register DI to point to the next write position since you are using JMP for looping. Your code fails to initialize the attribute byte of the position you are writing to so you have no idea what's going to be shown if anything.
-
yeah,but I know only a few,without "stosw" or "lodsb"...
???
-
; lodsb
mov al, [si]
inc si
;stosw
mov [es:di], ax
add di, 2
There's more to it than that, si/di can be decremented as well as incremented - really should do "cld" first to make sure the "direction flag" is "up".
Have you got the original code working? (Nasm won't assemble it, as posted)
Best,
Frank
-
There's more to it than that, si/di can be decremented as well as incremented - really should do "cld" first to make sure the "direction flag" is "up".
Good call, Frank. cld or std should always be made before using any stos instruction to ensure direction. These should be placed outside of the looping code for "normal" circumstances.
The original user may also want to add in
%define LOOPCOUNT 10
mov cx, LOOPCOUNT
cld
begin_loop:
.
.
.
stosw
loopnz begin_loop
or, since he's writing out the same value, make use of
%define LOOPCOUNT 10
.
.
.
mov ax, 0x742 ; attrib = 7, char = 'B' (0x42)
mov cx, LOOPCOUNT
cld
repnz stosw
and then finish execution by terminating properly rather than using CTRL-C to break out of a runaway program that, in the authors original code, will eventually bomb out with an access violation or something horribly wrong.
There are many ways to skin a cat and these are but a few. We're not going to have to cover video snow protection are we? ;D