I hate to just ask for code, but would anyone be willing to write me a small, heavily commented asm program? I'm trying to learn asm but nomatter how many times I read the tutorials, I just don't seem how it all works together. I was hoping I could maybe get a very basic asm program to look off of. Maybe like a 4 function calculator or something? I browsed ticalc, but didn't have any luck.

Figures, the one time I want a stupid, uselss program, I can't find one. Rolling Eyes

EDIT: And by the title Tiny program, I don't mean super optimized. I need to be able to understand it. Very Happy
Well, not sure if it'll be much help, but as its the only thing I've ever really coded in ASM - its all I got to show you.... So sorry in advanced if its not at all what you are looking for Laughing

This is my InstCirc program (I used latenite, so I don't have all that header crap - makes it easier Very Happy )


Code:
.module Program
.export ;idk wtf this does - latenite put it there so i leave it there :D

   Main
      ; Program entry point
      ;rcl ans and check its a list
      bcall(_rclans)
      ld a, (hl) ;hl = pointer to ans variable table
      cp ListObj ;check to see if its of the type list (first value)
      ret nz ;return if its not a list
      
      ;make sure dim(list = 3
      ld a, (de) ;de = pointer to ans variable data
      cp $03 ;I cheated here, the size is really the first 2 bytes ;)
      ret nz
      
      ;inc past the size info and save HL
      ex de, hl ;swap DE for HL since HL can be used with inc
      inc hl
      inc hl
      push hl ;save it for later
      
      rst $20 ;this is a shortcut for copy 9 to op1
                           ;which is also a bcall
      bcall(_convop1) ;converts the floating point number that
                                        ; is in op1 into a byte and a word
      ld (AppBackupScreen + 1), a ;save the 1 byte result for later
      
      ;restore HL and add 9
                ;I add 9 since thats how big each FP number is
      pop hl
      ld de, 9
      add hl, de
      push hl ;again, save it for later (currently at hl+2+9)
      
      rst $20
      bcall(_convop1)
      ld (AppBackupScreen), a
;Notice I stored this a before the last a?
;thats so I can load it at once w/ a 16bit register
;never forget about endianess
                                                     
      
      ;restore HL and add 9
      pop hl
      ld de, 9
      add hl, de ;no need to save it this time
      
      rst $20
      bcall(_convop1)
      
      ld c, a ;no need to save this a either, as it is getting used right away
      ld de, (AppBackupScreen) ;read the other two saved vals
      
      call FastCircle ;FastCircl takes c, d, and e as "arguments"
      bcall(_grbufcpy) ;update the screen
      ret
.endmodule

.include "FastCirc.inc" ;has the code for FastCircle


NOTE: THIS WILL NOT COMPILE IN ITS CURRENT FORM! If you want to compile it, you can either open up the InstCirc.lnp project file in Latenite, or add the necessary headers

NOTE2: Its only ever been compiled with brass...
Thanks. I don't really understand it at first glance, but your commenting is excellent. I'm sure I'll get it before too long. Thanks, again.

And I have brass and latenite installed.
foamy3 wrote:
Thanks. I don't really understand it at first glance, but your commenting is excellent.


Heh, without those comments I don't have an f'ing clue as to whats going on Laughing

Quote:
I'm sure I'll get it before too long. Thanks, again.


No problem. Just remember though, that the code I posted is about as optimized as I can get it (chip and Kerm helped optimize my original code), so thats part of the reason its a bit complicated (like the rst $20 stuff - i had no clue about that until chip or Kerm told me to use it instead Wink )
I probably should have made a new topic for this, but I don't really feel like spamming new threads.

Anyway, I tried to make a program that incremented one by one and displayed the answer. I assembled it in TASM. All I got was some goofy characters on the screen (in VTI).


Code:
.nolist
    #include    "ti83plus.inc"
.list
.org    $9D93
.db    t2ByteTok, tAsmCmp
   
    ld A, 1    ;loads 1 into register a
    INC A     ;adds 1 to a
   
    ld    hl, 0                    ;message displaying copied from
                                     ;learn asm in 28 days
    ld    (PenCol), hl     ;    "
    ld    hl, A               ; loads hl with register A (which
                                ;should be 2)
    b_call(_PutS)            ; Display the text
    b_call(_NewLine)
    ret




.end
.end


How many errors are there?

Code:

    ld    hl, 0                    ;message displaying copied from
                                     ;learn asm in 28 days
    ld    (PenCol), hl     ;    "
    ld    hl, A               ; loads hl with register A

Starting with this, all that loading PenCol with 0 results in is resetting the cursor. You can do this yourself with B_CALL(_NewLine), although it's slower. The biggest problem in this chunk is how you're doing "ld hl,a". The assembler sees this as ld (hl),a, and since hl is 0, it tries to write the value of a to $0000, which does nothing. If you want to load hl with the value of a, you need to do

Code:

   ld l,a
   ld h,0

Next chunk:

Code:

    b_call(_PutS)            ; Display the text
    b_call(_NewLine)
    ret

What you have here is what would display a string pointed to by HL. In this case, hl is 0, so it displays the first bytes of ROM page 0 until it reaches a 0, which is only five or so bytes, if I remember correctly. This explains why you're getting junk on the screen. To display a number that's in HL, you use the _DispHL romcall.
So, here's what I would do for such a program.

Code:

Insert header here...

   b_call(_ClrLCDFull) ;you're doing a homeup later, no telling what's there.
   xor a                     ;zero out a
   b_call(_HomeUp)    ;this is just easier for newbies to understand
loop:
   inc a                      ;add 1 to a
   ld l,a
   ld h,0                     ;load a to hl
   b_call(_DispHL)       ;display the number in hl
   b_call(_NewLine)     ;new line
   ret                         ;quit

It's worth noting that this will just display 1 and exit. If you wanted it to loop until you pressed something, you could add

Code:

   b_call(_GetCSC) ;check for keypresses
   or a                   ;did it return 0?
   jr z, loop            ;if so, loop back

just before the ret.

For a little more practice with some basic romcalls, here's a useless little program that will display the ASCII equivalent of every byte of memory until it reaches the end ($FFFF)or you press a key.

Code:

insert header

   ld hl,0                      ;zero hl
loop:
   push hl                     ;save hl (it gives a cool effect in the final program)
   b_call(_PutS)            ;print until it reaches a 0
   pop hl                      ;restore hl
   inc hl                       ;add 1
   ld a,h
   or l
   ret z                        ;see if we reached $FFFF (the register loops back to 0)
   b_call(_GetCSC)      ;check for keys
   or a                        ;anything pressed?
   ret nz                     ;if so, quit
   jr loop                    ;repeat

I'm spending too much time on IRC... I just typed /quit rather than /code
Wow. Thanks.

Now just a few questions.

Is loading it into HL the best way to display a number?
Is the 'jr z' like a TI-BASIC GOTO, with loop: being the Lbl?
How would you add 2 numbers? Do you just make a loop of adding one?
1: yes, loading into HL is at very least the easiest way to display a number.
2: jr z is a conditional jump, acting like "If condition:Goto X" in BASIC. It jumps to label if the zero flag is set.
3: adding two numbers is easy. Say you had a value in a, and you wanted to add 6 to it, just do "add a,6"
For LD, always check that what you are trying to do is valid first

http://nwps.ws/~dragonfire/Asmin28/lesson/day03.html#reg (check the "Valid arguments for LD" table Wink )
You guys are missing something important. He's loading the number 1 into hl; basically that's going to display the text starting at $0001 and ending when it reaches a zero. What you want to do is use PutC, but even then, you want an ascii "1", not the number one. Solution:


Code:
  ld A, 1    ;loads 1 into register a
    INC A     ;adds 1 to a
   
    ld    hl, 0                    ;message displaying copied from
                                     ;learn asm in 28 days
    ld    (PenCol), hl     ;    "
    add a,"0"                ; this will work correctly for digits 0-9 (know why?)
                                ;should be "1" here
    b_call(_PutC)            ; Display the text
    b_call(_NewLine)
 
Kerm, won't that end up displaying the number 2 though, as you start with A = 1, inc it (so a = 2), and then add the ASCII equivelent of 0. '0' + 2 == '2', no? So shouldn't it be ld a, 0 instead of ld a, 1?
Sorr,y he is adding 1+1, so it will output "2".
The Tari wrote:
3: adding two numbers is easy. Say you had a value in a, and you wanted to add 6 to it, just do "add a,6"


Would the answer then be saved into a?
Yes.
This post seemed to short...
Most of the mathematical operations performed get performed on the accumulator, a. For example:
add a,6 adds 6 to a and stores the result in a. If a > 255, then a is actually the value minus 256.
sub 6 is the same, except for subtraction. If a < 0, then a becomes a+256.
inc a increments a and stores the result. If it's 256, then it becomes 0.
dec a you get the drill.
rra a, rlc a, sll a, etc: same deal
KermMartian wrote:
inc a increments a and stores the result. If it's 256, then it becomes 0.

That should be 255.
I think he means that if it would be 256, it becomes 0.
No Kirb, I meant 256. If the incremented value, not the value before the increment, is 256, it is instead 0 and the carry flag is set.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement