It is currently Thu Feb 20, 2020 12:27 pm

 All times are UTC

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: BHI VS. BGTPosted: Fri Dec 16, 2011 3:39 pm

Joined: Fri Dec 16, 2011 12:32 am
Posts: 17
If I understand correctly, BHI is used when we are working with unsigned numbers and BGT is used when we are working with signed numbers. Which one should we use if we do CMP 4,6 that is 6-4=-2?BHI since both numbers are positive and unsigned or BGT since the result is negative? When choosing BHI or BGT do we just look at the range of numbers we will be working with or do we have to take into consideration the result also?

Top

 Post subject: Posted: Fri Dec 16, 2011 5:20 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1116
The numbers being compared are the key.

If the any of the numbers being compared might contain a negative number then use signed compares. If the numbers being compared contain only unsigned numbers then use unsigned compares.

_________________
Prof. Kelly

Top

 Post subject: Posted: Fri Dec 16, 2011 7:47 pm

Joined: Fri Dec 16, 2011 12:32 am
Posts: 17
profkelly wrote:
The numbers being compared are the key.

If the any of the numbers being compared might contain a negative number then use signed compares. If the numbers being compared contain only unsigned numbers then use unsigned compares.

Oh I see, thanks!

I would appreciate it if someone could also explain why it is that BGT branches when NVZ* + N*V*Z* = 1.

Can someone explain BGT as someone explained BHI to me in this manner:
BHI is true if C*Z*=1:
Subtracting a larger number from a smaller number will result in a negative number, which will set the carry flag. Subtracting equal numbers will result in 0, which will set the zero flag.

A number that is higher is neither negative nor zero, so both flags are cleared.

Top

 Post subject: Posted: Fri Dec 16, 2011 10:54 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1116
BGT Brances if N and V are equal and Z=0.

If the numbers are the same then Z=1.
For all other cases:
Comparing a larger number to a smaller number when both are the same sign will result in N=0, V=0.
Comparing a positive number to a negative number will result in N=1, V=1

Code:
; Compare 127 to 100
move.b  #127,d0     ; larger positive
sub.b   #100,d0     ; minus smaller positive, N=0, V=0, Z=0

; Compare 100 to 127
move.b  #100,d0     ; smaller positive
sub.b   #127,d0     ; minus larger positive,  N=1, V=0, Z=0

; Compare -100 to -127
move.b  #-100,d0    ; larger negative
sub.b   #-127,d0    ; minus smaller negative, N=0, V=0, Z=0

; Compare -127 to -100
move.b  #-127,d0    ; smaller negative
sub.b   #-100,d0    ; minus larger negative,  N=1, V=0, Z=0

; Compare -100 to 100
move.b  #-100,d0    ; smaller negative
sub.b   #100,d0     ; minus larger positive,  N=0, V=1, Z=0

; Compare 100 to -100
move.b  #100,d0     ; larger positive
sub.b   #-100,d0    ; minus smaller negative, N=1, V=1, Z=0

_________________
Prof. Kelly

Top

 Post subject: Posted: Mon Dec 19, 2011 7:34 am

Joined: Fri Dec 16, 2011 12:32 am
Posts: 17
profkelly wrote:
BGT Brances if N and V are equal and Z=0.

If the numbers are the same then Z=1.
For all other cases:
Comparing a larger number to a smaller number when both are the same sign will result in N=0, V=0.
Comparing a positive number to a negative number will result in N=1, V=1

Code:
; Compare 127 to 100
move.b  #127,d0     ; larger positive
sub.b   #100,d0     ; minus smaller positive, N=0, V=0, Z=0

; Compare 100 to 127
move.b  #100,d0     ; smaller positive
sub.b   #127,d0     ; minus larger positive,  N=1, V=0, Z=0

; Compare -100 to -127
move.b  #-100,d0    ; larger negative
sub.b   #-127,d0    ; minus smaller negative, N=0, V=0, Z=0

; Compare -127 to -100
move.b  #-127,d0    ; smaller negative
sub.b   #-100,d0    ; minus larger negative,  N=1, V=0, Z=0

; Compare -100 to 100
move.b  #-100,d0    ; smaller negative
sub.b   #100,d0     ; minus larger positive,  N=0, V=1, Z=0

; Compare 100 to -100
move.b  #100,d0     ; larger positive
sub.b   #-100,d0    ; minus smaller negative, N=1, V=1, Z=0

Thanks for answering my question. I don't understand two things.

Code:
; Compare -100 to 100
move.b  #-100,d0    ; smaller negative
sub.b   #100,d0     ; minus larger positive,  N=0, V=1, Z=0[/quote]

Why N=0 and V=1? Why isn't N=1? -100 - 100 is -200 which is a negative number.

Code:
; Compare 100 to -100
move.b  #100,d0     ; larger positive
sub.b   #-100,d0    ; minus smaller negative, N=1, V=1, Z=0

I don't understand why N=1 and V=1? 100-[-100]=200 which is positive.

I did run everything through the simulator and you are correct. But I am working everything out on my own on paper and these two things aren't clear to me.

Top

 Post subject: Posted: Mon Dec 19, 2011 10:06 am

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
The range of a signed byte is -128, %10000000, to + 127, %01111111

Quote:
Why N=0 and V=1? Why isn't N=1? -100 - 100 is -200 which is a negative number.

-200 won't fit in a byte as a signed number and wraps round to +56

Quote:
I don't understand why N=1 and V=1? 100-[-100]=200 which is positive.

+200 won't fit in a byte as a signed number and wraps round to -56

Lee

Top

 Post subject: Posted: Mon Dec 19, 2011 1:50 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1116
The "wrap around" to a number that is out of the range of signed numbers is indicated by V=1.

_________________
Prof. Kelly

Top

 Post subject: Posted: Tue Dec 20, 2011 9:36 am

Joined: Fri Dec 16, 2011 12:32 am
Posts: 17
profkelly wrote:
The "wrap around" to a number that is out of the range of signed numbers is indicated by V=1.

I worked all of it out on paper, everything makes sense. Thanks a lot to both of you for clearing up this concept for me!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 4 guests

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

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects