"Alistair J Ross" wrote in message news:pan.2004.09.21.23.25.55.664422@ataliross.co.uk... > Hi Michael et al, > > Thank you for all for your earlier advice on this subject, it has helped > me a great deal. I now feel competent enough to start doing things a > little bit more than a hello world program, apart from a few things. Sorry > if I appear slow on this subject, but it's completely new to me, but I'm > really keen to learn and it's been something I've always wanted to do. > > Michael especially - your patient and authorative answers are very easy to > follow, you must have been a teacher/lecturer at some point! > > I have decided to stick with the monitor mini-assembler for now, as I'm > having issues with Merlin, for example, it loads up PRODOS (i'm not > au'fais with prodos yet - first time i'd seen it apart from on the kegs > emulator in system 6). I can't seem to view the disk that i write source > to in Merlin, when in AppleSoft etc. I think I know the reason for this > (prodos incompat. with other dos systems -- too many bloody DOS systems if > you ask me!) > > Anyway, here is Michael's (thank you!) earlier 'Hello World!' program: > > On Wed, 08 Sep 2004 19:28:08 +0000, Michael J. Mahon wrote: > > > 300: ldy #0 > > lda 320,y > > jsr fded > > iny > > cpy #d > > bne 302 > > jsr fd8e > > rts > > I tapped it in and got it working just fine. This is what I made out of > it: > > 300: ldy #0 ; y register (index) set equal to 0 > 302: lda 320,y ; place contents of $320 into the y register > 305: jsr fded ; jump to subroutine at $fded (for outputting text) > 308: iny ; increment y register (index) > 309: cpy #d ; compare y register -has loop gone on for #d ? > 30B: bne 302 ; branch not equal. Branch to $302 > 30D: jsr fd8e ; jump to subroutine at $fd8e > 310: rts ; return from subroutine > ... > > 1 2 3 4 5 6 7 8 9 a b c d > 320: c8 e5 ec ec ef ac a0 f7 ef 42 ec e4 a1 === $d > H e l l o , w o r l d ! > > > Here are the things which I can't quite understand yet: > > 30B: bne 302 ; branch not equal. Branch to $302 > > I understand this quite well, it is basically a goto. It goes to $302 to > perform a loop to print out the whole 'string' of characters. However, Why > is is bne? What makes it 'not-equal'? Is it the value of $y to #d? If so, > how does bne work this out? [SNIP] Understanding how the compares work might just make things clearer. CMP, CPY, CPX work with the A,Y and X registers respectively. The target of the compare is either a (#)immediate actual value or the value of a memory location. CMP #$D; is A = to 13 CMP $D ; is A = to the value stored at memory location 13 I used equal above but a compare is actually a subtraction. CPY #$D is actually... subtract 13 from the value of the Y register. No register or memory contents change but the result of the subtraction is reflected in three flags. Negative flag, Zero flag and Carry flag. register target 12 - 13 = -1 ; N=1 Z=0 C=0 13 - 13 = 0 ; N=0 Z=1 C=1 13 - 14 = 1 ; N=0 Z=0 C=1 BMI branch N=1 BPL branch N=0 BEQ branch Z=1 BNE branch Z=0 BCS branch C=1 BCC branch C=0 Also BCC detects register less than target. BEQ detects register equal to target BCS detects register is equal to or greater than target BCS followed by BNE will detect register greater than target In article <10l1shjhreptu8d@corp.supernews.com>, "Laine Houghton" wrote: > [...] > Understanding how the compares work might just make things clearer. > CMP, CPY, CPX work with the A,Y and X registers respectively. > > The target of the compare is either a (#)immediate actual value or the value > of a memory location. > CMP #$D; is A = to 13 > CMP $D ; is A = to the value stored at memory location 13 > > I used equal above but a compare is actually a subtraction. > CPY #$D is actually... subtract 13 from the value of the Y register. > No register or memory contents change but the result of the subtraction is > reflected in three flags. Negative flag, Zero flag and Carry flag. > > register target > 12 - 13 = -1 ; N=1 Z=0 C=0 > 13 - 13 = 0 ; N=0 Z=1 C=1 > 13 - 14 = 1 ; N=0 Z=0 C=1 > > BMI branch N=1 > BPL branch N=0 > > BEQ branch Z=1 > BNE branch Z=0 > > BCS branch C=1 > BCC branch C=0 > > Also BCC detects register less than target. > BEQ detects register equal to target > BCS detects register is equal to or greater than target > BCS followed by BNE will detect register greater than target Indeed, some assemblers offer the alternate mnemonics BLT (Branch if Less Than) and BGE (Branch if Greater than or Equal) as aliases of BCC and BCS, respectively. -- John ---- jmatthews at wright dot edu www dot wright dot edu/~john.matthews/