ECE-1021

HOMEWORK #2

(Last Mod: 27 November 2010 21:38:42 )

ECE-1021 Home


You will write two variants of an ACME-1021 Assembly Language program that sorts the values stored in adjacent card locations. 

Example: Let's say that we want to sort the values stored on cards #13 through #18. When we start, the values stored on the cards might be:

After I am done running my program, I want those six cards to contain the following values:

You are to present each program in the same manner as the example problem that was worked out at the end of the section on Assembly Language in Module 2 that implemented two-card by two-card multiplication. Specifically, an algorithm was developed and  implemented in ACME-1021 Assembly Language, it was then translated to an actual ACME-1021 instruction deck, and finally it was executed for a some test data.

Be sure that you understand the difference between ACME-1021 Assembly Language and an ACME-1021 Instruction Deck! An assembly language instruction can take advantage of things like the EQU directives and the assembler's ability to evaluate constant expressions. At some point, however, those instructions get translated to the actual ACME-1021 instructions where the operands MUST be written as literal numbers with perhaps indirection operators ('*') before them.

PROGRAM A

In your first program, there are exactly four values that are stored on Cards #N through #(N+3). The value of N will be such that the values to be sorted will all fit into the upper half of the twenty card memory space - so somewhere between Cards #10 and #19. The value of N will also be known to you prior to translating your Assembly Language instructions to the instruction deck. You should use an EQU directive to permit the you to move this to another location by simply changing that one EQU directive. In order to ensure that no conflict exists with the new locations, simply don't use any of the upper memory for anything else.

Example: I want to move the contents of two cards to a location that is three cards higher in memory. I will know prior to translation where the first of the two cards is presently stored.

ORG 1  // Start program on Instruction Card #1

EQU FIRSTCARD (13)  // Set to the location of the first card 

SET (FIRSTCARD + 3), *FIRSTCARD

SET ( (FIRSTCARD+1) + 3), *(FIRSTCARD+1)

Now, if someone tells you that the first of the two cards is actually stored at location 11, all you have to change is the value in the EQU directive to 11 giving you:

EQU FIRSTCARD (11)  // Set to the location of the first card 

SET (FIRSTCARD + 3), *FIRSTCARD

SET ( (FIRSTCARD+1) + 3), *(FIRSTCARD+1)

Now you can translate your Assembly Code to a Program Deck:

  1. SET 14, *11 

  2. SET 15, *12

Notice that in the program deck, the operands are all literal values that may or may not be preceded with indirection operators. This is required and we were able to translate our Assembly to the Deck and obey this rule because every expression in our Assembly was a "constant expression" meaning that it didn't depend on the values stored on one of the cards or on any value that wasn't known to us at the time we translated the program.

Feel free to make up your own test data. But be sure that your program will work regardless of what the specific values that were used happen to be.

Hint: It may help to develop your first version of the program assuming that the cards are fixed at a specific location, say Cards #12 through #15. Get that working, then see what would have to change to move the data to Cards #14 through #17 and key those statements to a single EQU directive. 

PROGRAM B

In your second program, you will use the GET instruction to first get the number of values that are to be sorted and then to get the card number where the first value is stored. You may assume that the values entered will be adequate to place all of the values somewhere in upper memory.

Hint: Remember that the GET instruction is used to get a number from the user at the time that your program is executed. So it I have the instructions:

  1. GET 12

  2. GET 13

  3. GET *13

Then the first value entered by the user will get stored in Card #12. The second number will get stored in Card #13. The third number will get stored on the card whose number the user entered as their second input.

For instance, let's say that the user entered 25, 6, and 17 in response to these three instructions. Then after these three instructions were executed, the following cards would have been affected:

So, in your program, you will need two GET instructions. In response to the first one, the user might enter the value 6. In response to the second one the user might enter the value 12. This means that there are six values to be sorted and they can be found on cards #12 through #17.

To test your program, simply place random values in the entire upper memory (by just writing random values on those cards - you don't need to use a bunch of SET instructions). Then assume that, in this example, the values on those six cards (#12 through #17) are not really random - they are six values placed there by some other part of the program that now need to be sorted.