LESSON5:

    If.. Then.. Elsestatements allow the program to branch off in many different directions. ASM does not support these staments directly, but using CP along with JR/JPyou can acheive the effect.
 
Theseare the instructions/ideas that will be covered in this lesson:
CALL
RET
FUNCTIONS
 
CALL
  Call allowsyou to jump to a different location in the ASM program, while saving whereit was, so it can return to that location later. (see also ret)  If the condition cc is true then it jumps to the label. CC is OPTIONAL.
call _clrLCD   ; calls the ROMfunction to clear the LCD
call z,_clrLCD ; only calls the function if the Zeroflag is set
back to list of instructions

 RET
  RET, returnspower back to where the last CALL statement was made,or back the TI/OS-SHELL, if no CALLs where made.  It's actually similiarto the stack, but it's easier to explain it this way. If cc is true then the ret is executed.  CC isOPTIONAL
 
back to list of instructions

 FUNCTIONS
  Putting theCALL and RET commands together you are given a powerful way to modulateyour programs.  You can create functions that perform certain tasks,and even accept input and produce output.
  ld a,5
  call Add3  ; calls our function Add3which adds 3 to the reg. A
            ; and stores the new value in B
            ;NOW b=a+3, or 8
  ld c,b     ;c=b, c=8
  :
  .

Add3:
  ld b,a     ;b=a
  inc b      ;
  inc b      ;
  inc b      ;b=a+3
  ret       ;returns control to next line after CALL was made.

 
back to list of instructions
LESSON4     INDEX    
This is the end of the lesson, I do not gaurantee any correctnessof any statements made above.