following is Pmode #1 written by Alexei A. Frounze.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PMode tutorials in C and Asm ;;
;; Copyright (C) 2000 Alexei A. Frounze ;;
;; The programs and sources come under the GPL ;;
;; (GNU General Public License), for more information ;;
;; read the file gnu-gpl.txt (originally named COPYING). ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GLOBAL _read_msw, _read_cr0, _write_cr0
SEGMENT _TEXT PUBLIC CLASS=CODE USE16
_read_msw:
smsw ax
retn
_read_cr0:
mov eax, cr0 ; read CR0 to eax
mov edx, eax
shr edx, 16 ; dx:ax = CR0 (return value)
retn
_write_cr0:
push bp
mov bp, sp
mov eax, [ss:bp+4] ; eax = 32-bit parameter
mov cr0, eax
pop bp
retn
SEGMENT _DATA PUBLIC CLASS=DATA
in the _write_cr0, to refer the first parameter, why is the offset = 4? not 8? and could I just mov eax, [bp+8]? I tihink no ss segment register needed, am I right?
when calling write_cr0, where is (E)IP register saved?is it saved in stack?
question in the pm tutorial
Re:question in the pm tutorial
You're in 16-bit mode, all stack registers are 16 bits. Function before you pushes the 32-bit value. It jumps (pushes IP), push BP and then read a 32-bit value, which is 2x a 16-bit value. So, if you want the 32-bit value, read from the base + 2x 16-bit = base + 4.asmboozer wrote: in the _write_cr0, to refer the first parameter, why is the offset = 4? not 8? and could I just mov eax, [bp+8]? I tihink no ss segment register needed, am I right?
when calling write_cr0, where is (E)IP register saved?is it saved in stack?
Your IP is stored on the stack at BP+2. (right after the BP, which is at 0)
Re:question in the pm tutorial
I know now. but what's the difference between USE16, USE32, and their meaning? what's the default when using nasm?
Re:question in the pm tutorial
The use16 directive is an alternate way form of the [bits 16] directive. It tells the assembler to generate 16-bit real mode code. The use32/[bits 32] directive indicates that it should generate 32-bit code.asmboozer wrote: I know now. but what's the difference between USE16, USE32, and their meaning? what's the default when using nasm?
For most cases, 32-bit p-mode code is the default. The exception to this is when assembling a program as a flat binary format (i.e., one containing only raw machine code with no linkage or relocation data), since that format is used almost exclusively in 16-bit code such as MS-DOS .com files or boot sectors (at least up to the point where it switches to p-mode, if it does). It is possible to use the directives repeatedly in a single source file, to indicate when the code generation should switch from one type to the other.