Assigned | Wednesday, March 8th |
---|---|
Program Due | Tuesday, March 28th by 11:59pm (originally due 3/17) |
Updates: | Project due date has been extende from 3/17 to 3/28, due to the snow. |
The objectives of the programming assignment are 1) to gain further experience writing subroutines in assembly language 2) to learn how to pass parameters on the stack 3) to practice saving values on the stack for reusing registers 4) to gain further experience with loop control
For this assignment, you will write an assembly language subroutine that outputs the printable string version of a 32-bit unsigned number to standard output. For example, the number 456123 needs should be converted to the 6-char string "456123", and then printed out. The 32-bit value will be passed to your subroutine on the stack. (It will be the last thing pushed on the stack before the CALL instruction.) Your subroutine must preserve all registers (i.e., any registers that you use must be saved on the stack and restored before you return, even EAX). Your subroutine should do nothing else (not even print a linefeed).
To determine the values of the base 10 digits in the decimal representation of the number, you will use the division method (do not use repeated subtraction). Continuously dividing by 10 will give you the next rightmost digit as the remainder each time. The DIV instruction will divide the 64-bit value stored in EDX:EAX by the single 32-bit operand given. After the DIV instruction is executed, the quotient is stored in the EAX register and the remainder is stored in the EDX register. (See further discussion of the DIV instruction in Implementation Notes below.)
Implement your subroutine in a separate file, named prt_dec.asm
.
The entry point of your
subroutine must be called prt_dec. The "main program" will
reside in a separate file. A sample main program is provided for you (main3.asm), but you must make your own
test program as well, called mytest3.asm. Note: your test program must be in
a separate file, otherwise your subroutine will fail to compile with the
test program used for grading.
When you assemble your program, you must assemble each source file separately:
Then, you can run the main3.out file produced as usual. A sample run with the main3.asm file provided should look like:
Note: The graders will use a different main program to test your subroutine. Your test program should fully exercise your subroutine and check for cases that are not tested in main3.asm. You can use main3.asm as your template and just modify the test cases.
In the division method for converting a number to base 10, you will get the one's place first (the least significant digit), then the 10's place, then the 100's place, ... This is in the opposite order that the decimal number will be printed. The easiest way to handle this situation is to initialize some register to point to the end of the output buffer and loop backwards, decrementing the pointer as you store each character.
To repeat one more time: you are not allowed to print each digit separately with a separate write syscall!
Thus, you must include the following declaration in your prt_dec.asm file:
Another quirk is that the DIV instruction does not support immediate operands. So, you cannot divide by 10 by saying:
Before you submit your program, record some sample runs of your program using the UNIX script command. You should select sample runs that demonstrate the features supported by your program. Picking good test cases is your responsibility.
Use the UNIX submit
command on the GL system to turn in
your project. You should submit three files: (1) your assembly language
program, named as prt_dec.asm
, (2) the assembly language test program,
named as mytest3.asm
, and (3) the typescript
file of your sample runs. The UNIX command to do this should
look something like:
submit cs313_park proj3 prt_dec.asm mytest3.asm typescript