Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nasm assembler help

Status
Not open for further replies.

beyondsociety

Technical User
May 9, 2002
40
0
0
US
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.
 
detect_cpu:
count the number of bytes that the pop and push operations place onto and remove from the stack. if at the end of the routine the stack is not at its initial value the ret operation will cause a problem.

no_386:
every routine should end with a ret operation. you could ommit 'call message' and this would naturally overrun into 'message' but this is deemed bad programming.

you could introduce the proc and endp directives. this will add a little structure to your source by showing clearly the difference between relative jumps and calls.

example:

myprog proc near
call mysubroutine
jmp myprog
myprog endp

mysubroutine proc near
{blah}
cmp eax,0h
je mysubjump
{blah}
mysubjump:
{blah}
ret
mysubroutine endp

i beleive 'near' is default but i always put for clarity.
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top