News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

problem with ax

Started by lynx.arc, April 16, 2006, 12:35:15 AM

Previous topic - Next topic

lynx.arc

hi everyone;
i am new to assembly/vga programming. when i try to run this code, it does not switch to mode 13h. i found seperate solutions to get it to mode 13h:

- skipping the .386 directive
- replace  "mov   ax, 13h" with "mov   eax, 13h"
- replace  "mov   ax, 13h" with "mov   al, 13h ; mov ah, 0"

one of these are enough to get the program to mode 13h. but the question is: why? why does "mov   ax, 13h" not work?

and another question: if i skip the .386 directive, will i get the timings for 8086?

.386
.model small, stdcall

.stack
.data   
.data?

.code

start:

mov       ax, 13h ; change screen to 320x200x256 (13h)
int 10h

mov ah, 01h                 ; wait until a key is pressed
        int 21h

mov ax, 03h ; return to text mode
int 10h

mov ah,4Ch ; exit
int 21h

end start






MichaelW

#1
The problem is not with AX, but with the position of the .386 processor directive. The solution to the problem is to place the .386 processor directive after the model directive.

The long explanation is:

When a .386 or higher processor directive precedes the model directive MASM assumes that the segment word size is 32 bits instead of 16 bits, so MASM is encoding the "mov ax, 13h" instruction with an operand size prefix. To the processor this prefix selects the non-default operand size which in a 32-bit segment would be 16 bits, but in a 16-bit segment, the actual case here, the non-default operand size is 32 bits. So the processor is trying to move a 32-bit value into EAX, which makes the instruction two bytes longer than MASM encoded it, so the processor is advancing IP past the 2-byte "int 10h" instruction. You can verify this by adding two nops between the mov and int instructions, or by simply adding a second int instruction, either of which will correct the immediate problem.

eschew obfuscation

lynx.arc

thanks for the explanation. now i understand "why"..   :U

BytePtr

Some hints for you from my experience:

If you are using atleast TASM 3.x or MASM 6.x then u can use such layout:

.model small
.stack 200h
.data
.code
.startup

.exit
end


To wait keypress:
xor ah, ah
int 16h


.exit is same as mov ah, 4ch
int 21h
but ist alot easier to type than the 2 rows each time.

Assembly is hard enough, why make it harder(?), thats why you can save some typing work with such "trick".

Search in google for asm tuts and read them you will understand stuff abut different memory models, operands, asm program layout etc etc. Of course good book in your hand is better that watching ebook/tutorial on pc screen.

Good luck with learning asm.