What is the problem with this logic? ( IF C < 16 THEN.....
-
LASERACTIVEGUY
- Posts: 18
- Joined: 29 Dec 2015
What is the problem with this logic? ( IF C < 16 THEN.....
What is wrong with this logic... I am trying to build a 16 bit IF THEN statement... such as
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
30005 #0
30004 #0
30016- AD 35 75 LDA 30005
30019- C9 00 CMP #0
30021- 90 0A BCC 30033
30023- D0 07 BNE 30032
30025- AD 34 75 LDA 30004
30028- C9 0F CMP #15
30030- 90 01 BCC 30033
30032- 60 RTS
30033- 4C 40 75 JMP 30016
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
30005 #0
30004 #0
30016- AD 35 75 LDA 30005
30019- C9 00 CMP #0
30021- 90 0A BCC 30033
30023- D0 07 BNE 30032
30025- AD 34 75 LDA 30004
30028- C9 0F CMP #15
30030- 90 01 BCC 30033
30032- 60 RTS
30033- 4C 40 75 JMP 30016
-
LASERACTIVEGUY
- Posts: 18
- Joined: 29 Dec 2015
Re: What is the problem with this logic? ( IF C < 16 THEN..
Whoop... I this instance, I want to loop it back to the IF statement... creates an endless loop...
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: What is the problem with this logic? ( IF C < 16 THEN..
LASERACTIVEGUY wrote:
What is wrong with this logic... I am trying to build a 16 bit IF THEN statement... such as
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
Code: Select all
30005 #0
30004 #0
30016- AD 35 75 LDA 30005
30019- C9 00 CMP #0
30021- 90 0A BCC 30033
30023- D0 07 BNE 30032
30025- AD 34 75 LDA 30004
30028- C9 0F CMP #15
30030- 90 01 BCC 30033
30032- 60 RTS
30033- 4C 40 75 JMP 30016x86? We ain't got no x86. We don't NEED no stinking x86!
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: What is the problem with this logic? ( IF C < 16 THEN..
BigDumbDinosaur wrote:
LASERACTIVEGUY wrote:
What is wrong with this logic... I am trying to build a 16 bit IF THEN statement... such as
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
IF C < 16 THEN (Pass thru to argument...
(If failed...RTS)
Assume these are the current values...
Code: Select all
30005 #0
30004 #0
30016- AD 35 75 LDA 30005
30019- C9 00 CMP #0
30021- 90 0A BCC 30033
30023- D0 07 BNE 30032
30025- AD 34 75 LDA 30004
30028- C9 0F CMP #15
30030- 90 01 BCC 30033
30032- 60 RTS
30033- 4C 40 75 JMP 30016Code: Select all
org $7534
dcb 0Code: Select all
30016- AD 35 75 LDA 30005 ; A = *(30005)
30019- C9 00 CMP #0 ; this will always set C
30021- 90 0A BCC 30033 ; this branch is never taken
30023- D0 07 BNE 30032 ; if (A != 0) then done
30025- AD 34 75 LDA 30004 ; A = *(30004)
30028- C9 0F CMP #15 ; if (A < 15) then clear C else set C
30030- 90 01 BCC 30033 ; if (A < 15) then loop back
30032- 60 RTS ; else done
30033- 4C 40 75 JMP 30016 ; superfluous springboard
Last edited by barrym95838 on Thu Sep 07, 2017 4:05 am, edited 2 times in total.
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: What is the problem with this logic? ( IF C < 16 THEN..
BigDumbDinosaur wrote:
Your source code isn't making a lot of sense. What are these 300.. numbers? What does 30004 #0 mean? Ditto with 30005 #0?
Again, you never need a compare-to-zero instruction after a load instruction, or after a logic or arithmetic instruction either. It's a built-in, implied part of the instruction already. I suspect however from your "IF C < 16 THEN" line that the CMP #0 was supposed to CMP #16.
What is at 30005? Is it I/O? If it's RAM, you'll just re-load the same thing again, and keep getting the same result, right? The constants should usually be given descriptive names. Also, why not just branch directly to 30016, instead of to a jump instruction that sends it there anyway? You have a branch to a jump to go back to re-loading 30005 again.
I started trying to make this structured, but I now I thought I better find out better what you're trying to do first.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: What is the problem with this logic? ( IF C < 16 THEN..
It's highly obvious to me what he wants to do ... heck, it's in the title of the thread! I'm just hesitant to blurt out the answer, because I want to give him a chance to work it out for himself.
Mike B.
Mike B.
Re: What is the problem with this logic? ( IF C < 16 THEN..
LASERACTIVEGUY wrote:
What is wrong with this logic... I am trying to build a 16 bit IF THEN statement... such as
Code: Select all
$0016- AD 35 75 LDA $0005
$0019- C9 00 CMP #0
$0021- 90 0A BCC $0033
$0023- D0 07 BNE $0032
$0025- AD 34 75 LDA $0004
$0028- C9 0F CMP #15
$0030- 90 01 BCC $0033
$0032- 60 RTS
$0033- 4C 40 75 JMP $0016
Even then looking at the dissasembled code on the left the addresses don't match.
Re: What is the problem with this logic? ( IF C < 16 THEN..
Is nobody here ever reading previous answers? Mike B. already said that the numbers are base 10 (decimal) instead of base 16 (hex). I also like the way Mike writes comments in a program. In this case it makes really clear what is going wrong.
6502 sources on GitHub: https://github.com/Klaus2m5
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: What is the problem with this logic? ( IF C < 16 THEN..
LIV2 wrote:
The only way it makes sense is that all the leading 3's are actually supposed to be $s right?
Even then looking at the dissasembled code on the left the addresses don't match.
Even then looking at the dissasembled code on the left the addresses don't match.
He has a 16-bit little-endian unsigned integer named C at 30004 ($7534) and 30005 ($7535) and he wants to code:
Code: Select all
if (C < 16) {
then do something
} else {
do something else
}Mike B.
-
LASERACTIVEGUY
- Posts: 18
- Joined: 29 Dec 2015
Re: What is the problem with this logic? ( IF C < 16 THEN..
I am sorry about being a big pain in the butt about this (putting it mildly)...
I figured out what the bug was... take the basic
10 IF C<16 THEN C=C+1:GOTO 10
20 C=0:GOTO 10
Now take what I did...
10000 JSR A
10003 JSR B
10006 JSR (END..BACK TO COMPUTER PROMPT)
A IF C<16 THEN C=C+1:GOTO A
*(IF FAIL...RTS)
B C=0:GOTO A
The first time it fails... it RTS back to the JSR list...
afterwards... it processes B, and then jumps back to A...
however... the 2nd time it fails... the RTS goes back to the JSR
list and not BBB like I wanted.. therfore ending the program.
It was a mistake in logic.
To correct.. I replaced the RTS in the IF statement with a fake (GOTO NEXT LINE)...
the compiler on the 2nd pass determins where in memory those lines are... so it looks
up the list for the current line its on.. (then +1) to create a correct JMP instruction.
Also had to replace the END of program from the bottom of the JSR list to after the
very last compiled statement. Works much better... and just as its equiv applesoft program!
Also went thru a couple pdf manuals late last night on the internet and rewrote the rest of the
if statements for a<c a>c and a=c equivs and all checked out.
Thank you for your help!
I figured out what the bug was... take the basic
10 IF C<16 THEN C=C+1:GOTO 10
20 C=0:GOTO 10
Now take what I did...
10000 JSR A
10003 JSR B
10006 JSR (END..BACK TO COMPUTER PROMPT)
A IF C<16 THEN C=C+1:GOTO A
*(IF FAIL...RTS)
B C=0:GOTO A
The first time it fails... it RTS back to the JSR list...
afterwards... it processes B, and then jumps back to A...
however... the 2nd time it fails... the RTS goes back to the JSR
list and not BBB like I wanted.. therfore ending the program.
It was a mistake in logic.
To correct.. I replaced the RTS in the IF statement with a fake (GOTO NEXT LINE)...
the compiler on the 2nd pass determins where in memory those lines are... so it looks
up the list for the current line its on.. (then +1) to create a correct JMP instruction.
Also had to replace the END of program from the bottom of the JSR list to after the
very last compiled statement. Works much better... and just as its equiv applesoft program!
Also went thru a couple pdf manuals late last night on the internet and rewrote the rest of the
if statements for a<c a>c and a=c equivs and all checked out.
Thank you for your help!
-
LASERACTIVEGUY
- Posts: 18
- Joined: 29 Dec 2015
Re: What is the problem with this logic? ( IF C < 16 THEN..
He's obviously working in base 10, BDD, at least in the source. And 30004 #0 is his way of saying
Code:
org $7534
dcb 0
.......NOPE... your wrong. When I started learning assembly.. I couldn't take the hex, so I built an assembler that
did everything entirely in decimal... and then has my Assembler.. in basic.. poke the values of the assembly code
I translated from hex... its actually quite a good assembler (for me anyway)... there are also provisions for typing in
other peoples code by putting $ infront of the number and it converts it to decimal for me... can I show a pic here?
Code:
org $7534
dcb 0
.......NOPE... your wrong. When I started learning assembly.. I couldn't take the hex, so I built an assembler that
did everything entirely in decimal... and then has my Assembler.. in basic.. poke the values of the assembly code
I translated from hex... its actually quite a good assembler (for me anyway)... there are also provisions for typing in
other peoples code by putting $ infront of the number and it converts it to decimal for me... can I show a pic here?
Re: What is the problem with this logic? ( IF C < 16 THEN..
Quote:
.......NOPE... your wrong.
6502 sources on GitHub: https://github.com/Klaus2m5
Re: What is the problem with this logic? ( IF C < 16 THEN..
LASERACTIVEGUY wrote:
...
I couldn't take the hex
...
I couldn't take the hex
...
Re: What is the problem with this logic? ( IF C < 16 THEN..
LASERACTIVEGUY wrote:
.......NOPE... your wrong. When I started learning assembly.. I couldn't take the hex, so I built an assembler that
did everything entirely in decimal...
did everything entirely in decimal...
There's something to learn here when someone decides creating an assembler is easier than learning a new number system.
As a note, I appreciate that it's like near impossible to get an output of an assembler in anything but hexadecimal (in terms of the assembler listing, and the addresses and op codes and what not), unless, of course, you're running on a PDP-* or something.
However, most any assembler will happily take decimal arguments:
Code: Select all
.ORG 10000
START LDA 30001
BNE TOOBIG
LDA 30000
CMP #16
BCS TOOBIG
; 30000 is less than 16...
TOOBIG ; 30000 is to big...
Hexadecimal is popular because it concisely, and regularly, represents 8 bit values well.
The only reason I can think of why the PDP continued with its fixation on octal, on a 16 bit architecture is simply momentum from other machines with other word sizes. I always felt octal was rather horrible. But that's me.
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: What is the problem with this logic? ( IF C < 16 THEN..
LASERACTIVEGUY wrote:
When I started learning assembly.. I couldn't take the hex...
Hex is "strange" to human beings because we are accustomed to base-10, which comes from having 10 fingers and 10 toes. I supposed if we had evolved with eight fingers and eight toes we'd be counting in octal.
x86? We ain't got no x86. We don't NEED no stinking x86!