OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 9:32 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [SOLVED]How to use the CMP instruction
PostPosted: Tue May 20, 2014 7:19 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 06, 2014 4:23 pm
Posts: 62
I have a problem with my code. I don't know how to debug assembly. I have a problem with the
Code:
cmp
command. Here is the code:
Code:
    BITS 16

start:
    in al, 0x92
    test al, 2
    jnz skip
    or al, 2
    and al, 0xFE
    out 0x92, al
    jmp skip

skip:
    mov ax, 07C0h
    add ax, 288
    mov ss, ax
    mov sp, 4096
    mov ax, 07C0h
    mov ds, ax
    mov si, welcome
    call print_si
    jmp term
    welcome db 'Welcome to starfruit', 0

print_si:
    mov ah, 0Eh

.repeat:
    lodsb
    cmp al, 0
    je .done
    int 10h
    jmp .repeat

.done:
    ret
    times 510-($-$$) db 0
    dw 0xAA55

term:
    int 80h
    [color=#FF0000]cmp 80h, 0x65[/color]
    je .done
    [color=#FF0000]cmp 80h, 0x76[/color]
    je vdisplay
    [color=#FF0000]cmp 80h, 0x62[/color]
    je boothdd
    jmp error

error:
    mov si, emsga
    call print_si
    mov si, emsgb
    jmp term
    emsga db 'Commands are 1 byte long', 0
    emsgb db 'Try v, b, or e', 0

vdisplay:
    mov si, version
    call print_si
    jmp term
    version db 'Version 1.00', 0

boothdd:
    mov si, haltmsg
    call print_si
    hlt
    haltmsg db 'System Halt', 0

I highlighted the lines NASM told me was the problem. But I don't see a problem(I'm new to assembly).
This is how I build it:
Code:
nasm -f bin -o boot.bin boot.asm
dd status=noxfer conv=notrunc if=boot.bin of=floppy.flp
mkisofs -o disc.iso -b floppy.flp

Help?

_________________
Building an operating system is like building an airplane, you don't want it to crash.


Last edited by bashcommando on Tue Jan 20, 2015 3:48 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Help with my OS
PostPosted: Tue May 20, 2014 7:49 am 
Offline
Member
Member

Joined: Tue Aug 14, 2012 8:51 am
Posts: 92
You added code after the end. Everything after 0xAA55 is not included in the bootsector, so you jump to a location that contains random values, which causes an exception, which ultimately results in the pc rebooting


Top
 Profile  
 
 Post subject: Re: Help with my OS
PostPosted: Tue May 20, 2014 7:56 am 
Offline
Member
Member
User avatar

Joined: Wed Aug 21, 2013 3:53 am
Posts: 449
Location: Asia, Singapore
Code:
int 80h

?
Quote:
cmp 80h, 0x65

So you're trying to check if 0x80 = 0x65? Do they? :)
The CMP instruction does exactly what it says it compares two operands and sets the (E/R)FLAGS accordingly. Like,
Quote:
cmp ax, 7 -- Is AX = 7?
If AX is equal to 7 IIRC the ZF (Zero Flag) will be set, and you can use JZ or JE.
JE/JZ AddressX -- Jump to AddressX if ZF set

Have a look at the x86 jump instructions here: http://www.unixwiz.net/techtips/x86-jumps.html
Similarly, you can use:
Quote:
cmp ax, [7] -- Is AX = value at address 7?

_________________
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)


Top
 Profile  
 
 Post subject: Re: Help with my OS
PostPosted: Tue Jan 20, 2015 2:02 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 06, 2014 4:23 pm
Posts: 62
AbstractYouShudNow wrote:
You added code after the end. Everything after 0xAA55 is not included in the bootsector, so you jump to a location that contains random values, which causes an exception, which ultimately results in the pc rebooting

I at least know how to reboot it now. :lol:

_________________
Building an operating system is like building an airplane, you don't want it to crash.


Top
 Profile  
 
 Post subject: Re: [SOLVED]How to use the CMP instruction
PostPosted: Tue Jan 20, 2015 5:40 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
I recommend you take a look at this reference. It has everything you ever wanted to know about programming for an Intel processor, including the instruction set reference for CMP.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: [SOLVED]How to use the CMP instruction
PostPosted: Wed Jan 21, 2015 8:29 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 06, 2014 4:23 pm
Posts: 62
eryjus wrote:
I recommend you take a look at this reference. It has everything you ever wanted to know about programming for an Intel processor, including the instruction set reference for CMP.

Thanks but I already figured it out, you can't use cmp with 2 hexadecimal values without storing it in a variable.

_________________
Building an operating system is like building an airplane, you don't want it to crash.


Top
 Profile  
 
 Post subject: Re: [SOLVED]How to use the CMP instruction
PostPosted: Wed Jan 21, 2015 10:08 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Why would you even want to compare two constants in the first place?

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: [SOLVED]How to use the CMP instruction
PostPosted: Wed Jan 21, 2015 10:53 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 06, 2014 4:23 pm
Posts: 62
Combuster wrote:
Why would you even want to compare two constants in the first place?

You see, a year ago I thought 0x80 was a memory location not a constant. I needed to use a interrupt, then again I wasn't using linux so int 80h would not have worked anyways.

_________________
Building an operating system is like building an airplane, you don't want it to crash.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 155 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group