LESSON 5:

    If.. Then.. Else statements allow the program to branch off in many different directions.  ASM does not support these staments directly, but using CP along with JR/JP you can acheive the effect.
 
These are the instructions/ideas that will be covered in this lesson:
CALL
RET
FUNCTIONS
 
CALL
  Call allows you to jump to a different location in the ASM program, while saving where it 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 ROM function to clear the LCD
call z,_clrLCD ; only calls the function if the Zero flag is set
back to list of instructions

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

 FUNCTIONS
  Putting the CALL and RET commands together you are given a powerful way to modulate your programs.  You can create functions that perform certain tasks, and even accept input and produce output.
  ld a,5
  call Add3  ; calls our function Add3 which 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     LESSON6
This is the end of the lesson, I do not gaurantee any correctness of any statements made above.
© 1997 mindless productions