Click here to go to the SI Home Page
.

PhilhourHal 9000 Computer

ALSI: An Assembly Language for SI students

The goal of this project is to familiarize students with the MOST basic processes a computer is capable of. So we are writing down the minimum properties a language should have for basic functionality. Throughout this course we'll be using Java - a higher level language - but it helps to be constantly thinking of what, ultimately, the computer is understanding. To be clear: this is not a real language, and no computer will actually understand it -- we are just using it to play around with basic ideas.

Most recent update July 30, 2008 1:48 PM

Minimum Language Properties

  • Variable data storage
    • ALSI allows the programmer to store variable data in only two places, called A and B
    • ALSI relies entirely on a 8-bit binary number system
    • To set the a variable to a value , use the following syntax:
      • SET A 00000101
        • Note: this sets A to 00000101, which is 5 in binary
      • SET A B
        • Note: this sets A to whatever value B has
    • Variables start with value 00000000 unless otherwise specified
  • Input/output (I/O)
    • A value can be read in from the user (in 8-bit binary notation) with
      • INPUT A
    • A value can be displayed to the user (again, in 8-bit binary notation) with
      • OUTPUT A
    • A text statement enclosed in quotations can be displayed to the user with
      • OUTPUT "<text statement>"
      • for example:
        • OUTPUT "End of program."
  • Conditional branching
    • ALSI can compare two values and execute further statements based on the results of the comparison.
    • The syntax is as follows:
      • IFEQUAL <value1> <value2> <do the following> ELSE <do something else>
    • For instance, suppose we wanted to see if A is equal to 5 and, if it is, set B equal to 1. If A is not equal to 5, set B equal to 0. The code would look like this:
      • IFEQUAL A 00000101 SET B 00000001 ELSE SET B 00000000
    • In addition to IFEQUAL, we also have IFLARGER. The following sets each of B and A to the larger of the two:
      • IFLARGER A B SET B A ELSE SET A B
  • Looping repetitive operations
    • ALSI can do repetitive operations as well.
    • The syntax is as follows:
      • DO <number of times> TIMES
      • <operation1 to be repeated>
      • <operation 2 to be repeated>
      • ...
      • LOOP
    • So if we wanted to print out "HELLO" five times, we would write:
      • DO 00000101 TIMES
      • OUTPUT "HELLO"
      • LOOP
    • Note that you can also use a variable to tell you how many times to loop:
      • SET A 00000101
      • DO A TIMES
      • OUTPUT "HELLO"
      • LOOP
    • Use the END command to end a program entirely
  • Boolean Mathematical Operations
    • ALSI allows for simple math processes using Boolean logic.
    • A variable can be multiplied by 2 by shifting the bits to the left using LSHIFT. For instance, to multiply the number 5 by 2:
      • SET A 00000101
      • LSHIFT A
      • OUTPUT A
      • ... this will output 00001010, which has value 10 in binary
    • A variable can be divided by 2 by shifting the bits to the right using RSHIFT.
    • Note that when you shift right or left, new numbers that appear at the right or left end of the number are always zeroes.
    • Other math calculations are possible in principle, but not available in ALSI
  • Sub-routines
    • ALSI allows the program to write subroutines that can be accessed multiple times. The syntax is as follows:
      • SUBROUTINE <name of subroutine>
        • Note: this is used to tell ALSI we are beginning a subroutine
      • GOSUB <name of subroutine>
        • Note: this is used to tell ALSI to go to the subroutine and execute what's inside it
      • RETURN
        • Note: this is used to tell ALSI to come back from the subroutine
      • END
        • Note: Use the END command to end a program entirely

Sample Programs

  • The following program will tell you whether the number you have entered is odd or even. It works by noting that all odd numbers will have a 1 in the rightmost "ones" bit (so 00001001 and 00000111 are odd, while 00001000 and 00000110 are even). So if we left-shift any odd number that is input by the user seven times, it should equal 10000000; whereas if we left-shift any even number that is input by the user seven times, it should equal 00000000.
    • OUTPUT "Enter a number in 8-bit binary notation."
    • INPUT A
    • DO 00000111 TIMES
    • LSHIFT A
    • LOOP
    • IFEQUAL A 10000000 OUTPUT "Your number is odd." ELSE OUTPUT "Your number is even."
  • The following program asks the user for two numbers and will print out the word "LOOPY" a number of times equal to the product of the two. So, for instance, if you entered in 00000011 ("3") and 00000101 ("5") the word "LOOPY" would be printed fifteen times. This program relies on the concept of a "nested loop" and uses a subroutine as well. Some lines that "go together" are color coordinated. The subroutine -- called Repeater -- is indented for clarity.
    • OUTPUT "Enter a number in 8-bit binary notation."
    • INPUT A
    • OUTPUT "Enter a second number in 8-bit binary notation."
    • INPUT B
    • DO A TIMES
    • GOSUB REPEATER
    • LOOP
    • END
      • SUBROUTINE REPEATER
      • DO B TIMES
      • OUTPUT "LOOPY"
      • LOOP
      • RETURN

Test Your Understanding

  1. Write a problem in ALSI that inputs a number from the user. If the number is greater than or equal to 4, the program should output that number divided by 4. If the number is less than 4, the program should output a message saying "I can't divide such a small number."
  2. Write a problem in ALSI that inputs two numbers from the user and outputs a text statement saying which is lower and which is higher.

 

 

 

 

 

 

 



Can't find what you're looking for or
see a problem with the web site? Let us know!

© Copyright 2010, St. Ignatius College Preparatory
2001 37th Avenue, San Francisco, CA  94116 · (415) 731-7500