Assignment three questions and answers

Here are some notes about assignment three (some in Q&A format, but I didn't comply with that format when it would have been silly). Suggestions for additions to this list are welcome (via e-mail).

Also see:

If you like, you can put ~ajr/258/bin into your "path" so that you can just type commands such as "vasm", etc, without the full path name every time. Type something like this:

        set path = ($path ~ajr/258/bin)
After that you can simply type the name of my programs, e.g. "vasm q3", "velma a.out".

When you log out and back in, or if you switch to a different shell window, you'll have to type the above 'set' command again. I think that might be the best arrangement for now. Ask by e-mail about fancier alternatives.


To be clear: All of your submitted code for this assignment should be in the symbolic form, e.g. write "MOV 123, R5", not 14500123. You might want to assemble your program to run it, but you must submit the symbolic form file (which is the input to vasm), not the binary file (which is the output of vasm).


I think a lot can be learned by typing in code and assembling it and running it through the disassembler.

Another useful investigative technique is

        ~ajr/258/bin/velma -v a.out | less
which will allow you to page up and down the output from the trace, in the cases where it's very long (or an infinite loop). Press 'q' to quit the "less" pager.


There is no standard for commenting for assembly-language programs in this course.

But the grader has to be able to read your program. It's fairly unusual for even small assembly-language programs to be readable without any comments at all.

In "vasm", comments are introduced by a semicolon, and run to the end of the line.
Blank lines are allowed, and thus so are lines which are only comments.


Remember that just about everything is in octal (base eight).

The input to the "vasm" program is in octal. This is not an attribute of the VELMA architecture, which is all about zeroes and ones; it's an attribute of the assembler. If you write "MOV# 123, R0", it emits the instruction which will put the number 1238 into R0, not the number 12310. But I could have written the assembler to do the latter instead, it just would have been very unusual. As discussed in lecture, we tend to use a base which is a power of two so that we can see the bits. For example, the value 41232345 has the sign bit on, which you can immediately tell by seeing that the eighth digit from the right is >= 4. It takes some practice, and we haven't had a use for this yet, but we certainly will when talking about I/O later in the course.

All values on the assignment handout are in octal, except for the date and the course number.


Q: What is "X" in question 1?

A: It is the number which your program counts the number of '1' bits in. For example, for the supplied "123" (base 8), the answer is 4. If your file says "X: .WORD 123" at the end, then it should HALT with 4 in R0. If the grading software substitutes that to say "X: .WORD 7" and assembles and runs your program, then it should HALT with 3 in R0 (because 7 is "111" in binary).


Q: Question 4 says to leave our code in the symbolic form. Does this mean we submit our answer to question 1 in octal?

A: No. Submit everything in symbolic form in plain text files. Your submissions for questions 1, 3a, and 4 should be usable as input to "vasm" without complaint.


Q: Can we use register R6 as a general purpose register for question 1?

A: Yes. So long as you don't do any JSRs in the entire program (which you won't in question 1), R6 is not special.

Q: I still need more registers.

A: You can use main memory locations when you run out of registers; it just might take more instructions.

Or you can see if there are opportunities for further cleverness in your use of registers.


Q: Does "ADD R0, R1" put the sum into R0 or R1?

A: Into R1.

Q: I have a textbook here which says it puts the sum into R0. Is it wrong?

A: Unfortunately, not necessarily. This is not consistent across assembly languages. A generic discussion of assembly language programming could reasonably use either ordering.

I've been consistently using the PDP-11 ordering in class, which I've adopted for VELMA. For the PDP-11 or VELMA, the effective address description after the comma is the target. Some assembly languages do it the other way around. This is a syntactic issue in the assembly language; it doesn't affect the numeric machine language; in the numeric machine language, the issue arises all over again and must be documented again based on the bit layout.

It's really a shame that this is not consistent across assembly languages, because obviously this is extremely crucial. However, it indeed isn't consistent. You always have to ask (for each CPU).


Q: Does "CMP R1, R2" subtract R2-R1 or R1-R2?

A: It subtracts R2-R1, just like the SUB instruction of the same format.

(In this case, the PDP-11 differs; one of the aspects in which VELMA is a simplified PDP-11 is that in VELMA, the CMP operand order does not vary from the SUB operand order.)


Q: Could you supply the code for question 2 on-line so that I can run it?

A: I think that you need to analyze the program, not run it. I don't think this problem can be solved by testing.

Q: So are you going to make me type it in?

A: No, I guess not; here it is.


Q: How do we arrange for a value to be in a particular memory location for testing?

A: For one, you can write a few extra machine-language instructions to set stuff up for testing, to which you concatenate your program when you want to test it.

E.g. you can write

    MOV #3, R0
    MOV R0, 500
to initialize memory location 500 with the value 3.

Or you can use the ".ORG" pseudo-op in your assembly code file. ".ORG" (for "origin") says to start laying down code at some different place.

Example:

    [your question 4 main program and subroutine go here, including the HALT]

    .ORG 1000
    .WORD 3
    .WORD 4
    .WORD 3
    .WORD 67
    ... [etc... this is your 50 words of data which should start off in
         memory locations 1000 through 1050 (semi-inclusive).]


[main course page]