Control Structures and I/O in SAL

Tom Kelliher, CS 220

Sept. 17, 1997

Announcements

Advice on using HLL and converting to SAL.

Assignment

Friday will be a lab session to write and run a SAL program. Here's the description:

Write a SAL program to read an integer, n, then read n integers and output the sum of the positive integers read.
Come to class with HLL pseudocode to solve the problem.

Control Structures

  1. Unconditional branch: b target

  2. Conditional branches with implicit comparison to 0: bltz, bgtz, blez, bgez, beqz, bnez. Example: beqz divisor, error

  3. Conditional branches which compare two operands: blt, bgt, ble, bge, beq, bne. Example: beq i, j, endif

Examples

  1. if (i >= 0)
       j = 1;
    else
       j = -1;
    

  2. if (i <= -2 || i >= 2)
       i *= i;
    else if (i == 0)
       i = i / j;
    else
       j = i;
    

  3. for (i = 1, sum = 0; i < 1025; i *= 2)
       sum += i;
    

  4. while (i < 1000)
    {
       if (i % j == 0)
          break;
    
       i += k;
    }
    

I/O

  1. get input --- Input operation. input can be a .word, .float, or a .byte. Entire line read for the former two.

  2. put output --- Output operation. output can be a .word, .float, or a .byte. No newline added. (So, how do we get a newline?)

  3. puts string --- Output a string.



Thomas P. Kelliher
Tue Sep 16 17:45:30 EDT 1997
Tom Kelliher