beyondsociety
Technical User
I m creating a program that will detect the cpu with nasm
as my assembler. When I compile the code, it will compile it to a .com file. When I try to run it, I get a:
checking for 386 processor: found it!
memory allocation error
cannot load command, system halted
when I run it from a dos prompt or from the .com file.
Here is the Code:
org 100h
bits 16
jmp start
processormsg db "Checking for 386+ processor: ",0
need386 db "Sorry... The Asssembler needs a 386+ processor and cannot continue",13,10,0
found386 db "Found it!",13,10,0
detect_cpu:
mov si,processormsg ; tells the user what were doing
call message
; test for a 386+ processor (flag bits 12-15 are set)
pushf ; save the flags orginal value
xor ah,ah ; ah = 0
push ax ; copy ax into the flags
popf ; with bits 12-15 clear
pushf ; read flags back into ax
pop ax
and ah,0f0h ; check if bits 12-15 are set
cmp ah,0f0h
je no386 ; no 386 detected
mov si,found386
call message
ret ; no 286, so at least 386
no386:
mov si,need386 ; tell the user the problem
call message
; ----------------------------------------------------------
message: ; dump ds:si to screen
lodsb ; load byte at ds:si into al
or al,al ; test if character os 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call bios
jmp message
done:
ret
; ----------------------------------------------------------
start:
call detect_cpu
call message
ret
------------------------------------------------------------
Can anybody help me, I would appreciate it. Also for some reason nasm will let me add a start: label but when I try to end the program with end (end start) it won't compile. It works when I use the command ret (return).Does anybody know why nasm does that.
as my assembler. When I compile the code, it will compile it to a .com file. When I try to run it, I get a:
checking for 386 processor: found it!
memory allocation error
cannot load command, system halted
when I run it from a dos prompt or from the .com file.
Here is the Code:
org 100h
bits 16
jmp start
processormsg db "Checking for 386+ processor: ",0
need386 db "Sorry... The Asssembler needs a 386+ processor and cannot continue",13,10,0
found386 db "Found it!",13,10,0
detect_cpu:
mov si,processormsg ; tells the user what were doing
call message
; test for a 386+ processor (flag bits 12-15 are set)
pushf ; save the flags orginal value
xor ah,ah ; ah = 0
push ax ; copy ax into the flags
popf ; with bits 12-15 clear
pushf ; read flags back into ax
pop ax
and ah,0f0h ; check if bits 12-15 are set
cmp ah,0f0h
je no386 ; no 386 detected
mov si,found386
call message
ret ; no 286, so at least 386
no386:
mov si,need386 ; tell the user the problem
call message
; ----------------------------------------------------------
message: ; dump ds:si to screen
lodsb ; load byte at ds:si into al
or al,al ; test if character os 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call bios
jmp message
done:
ret
; ----------------------------------------------------------
start:
call detect_cpu
call message
ret
------------------------------------------------------------
Can anybody help me, I would appreciate it. Also for some reason nasm will let me add a start: label but when I try to end the program with end (end start) it won't compile. It works when I use the command ret (return).Does anybody know why nasm does that.