Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

nasm assembler help

nasm assembler help

nasm assembler help

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

           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

           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

; ----------------------------------------------------------

           call detect_cpu
           call message



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.

RE: nasm assembler help

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.

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.


myprog proc near
 call mysubroutine
 jmp myprog
myprog endp

mysubroutine proc near
 cmp eax,0h
 je mysubjump
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!"

RE: nasm assembler help

you forgot a POPF before RET in detect_cpu

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close