Author Topic: cmp instruction  (Read 11889 times)

nobody

  • Guest
cmp instruction
« on: October 21, 2007, 01:28:17 PM »
I try to compare two numbers, one is in CH and another its the number itself.
But isnt works!!! What i did wrong?
Follow the code:

mov ah,2
int 0x1a

;here i suposed 10
cmp ch,0xa
;if not equal
jnz difrent

;do something if is equal...

difrent:
;any code and finished

Even i knowing thats equal it jmp to difrent... Whats wrong?
P.s: In debug.exe (windows) this code works fine.

nobody

  • Guest
Re: cmp instruction
« Reply #1 on: October 21, 2007, 03:27:11 PM »
I can't explain why it works in Windows. Are you sure? Unless you're running an old Sperry, this interrupt returns its results in BCD, so 0xa shouldn't be a valid value. If it were 10:00, I'd expect to see 0x10 in ch. Try it again in DEBUG - pay attention to the carry flag after the "int 0x1a" (set if error), and what's in ch. Something's wrong here, and your code for the "cmp" looks fine. I just wouldn't expect to ever see 0xa!

(After doing "something if it's equal", you probably want to jump to "someplace else", rather than "fall through" into the "do something if different" code, or you'll do both. Could this be confusing you?)

Best,
Frank

nobody

  • Guest
Re: cmp instruction
« Reply #2 on: October 21, 2007, 11:31:44 PM »
Code: [Select]
--------B-1A02-------------------------------
INT 1A - TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS)
AH = 02h
CF clear to avoid bug (see below)
Return: CF clear if successful
   CH = hour (BCD)
   CL = minutes (BCD)
   DH = seconds (BCD)
   DL = daylight savings flag (00h standard time, 01h daylight time)
CF set on error (i.e. clock not running or in middle of update)
Notes: this function is also supported by the Sperry PC, which predates the
 IBM AT; the data is returned in binary rather than BCD on the Sperry,
 and DL is always 00h
MS-DOS/PC DOS IO.SYS/IBMBIO.COM use this function to detect if a RTC
 is preset by checking if the returned values are non-zero. If they
 are, this function is called one more time, before it is assumed
 that no RTC is present.
BUG: some BIOSes leave CF unchanged if successful, so CF should be cleared
 before calling this function
SeeAlso: AH=00h,AH=03h,AH=04h,INT 21/AH=2Ch

> Even i knowing thats equal it jmp to difrent... Whats wrong?

Your code is full of silly typos and other bugs :-(

> P.s: In debug.exe (windows) this code works fine.

You know, 1A is a BIOS INT, and you can't use BIOS INT's from your silly "windows" anyway ... thus your code is just nonsense :-(

To play with CMP instruction, avoid any INT next time ;-)

nobody

  • Guest
Re: cmp instruction
« Reply #3 on: October 21, 2007, 11:54:15 PM »
In Windows - save 64-bit Vista? - bios ints are emulated. Dosemu seems to emulate int 1Ah correctly. If you're seeing 0Ah in ch, it *isn't* being emulated corrrectly! (would indicate that it's ':' o'clock! :)

Again, what's the state of your carry-flag?

Best,
Frank