Docsity

CS 061 Assignment 6: Decimal to Binary Conversion and Array Processing, Assignments of Computer Science

Toggle sidebar
bg1
CS 061 โ€“ Computer Org. & Assembly Lang. Fall - 2003
Assignment 6 โ€“ due Wednesday 11/19, 11 pm (secure server turnin)
1. Re-write your decimal to binary conversion program as a subroutine.
The main routine should ask the user to input a decimal integer in the range 0 to 32,767, and pass
to the subroutine a) the address of the start of the ASCII array, and b) the number of digits stored in
the array, which must be <= 5.
The subroutine will process the array, and return the corresponding binary value in a register.
2. Now expand this program to ask the user to input 10 integers (0 to 32,767), and build an array of
the corresponding binary numbers.
e.g. (using 5 numbers instead of 10):
the user inputs the numbers:
7
15
2
25
0
the end result is an array, starting at address (say) x3400:
0000 0000 0000 0111
0000 0000 0000 1111
0000 0000 0000 0010
0000 0000 0001 1001
0000 0000 0000 0000
3. Now add 100 to each of the numbers in the array, and output the new values as decimal numbers
(ii.e.as ASCII characters). Your binary to decimal conversion should also be written as a subroutine
which takes a single 16-bit binary number in a register, and returns a) the address of the start of the
ASCII array, and b) the number of digits stored in the array, which must be <= 5. (in other words,
exactly the inverse of the decimal to binary subroutien in 1).
So the output from the above example would be:
107
115
102
pf2

Partial preview of the text

Download CS 061 Assignment 6: Decimal to Binary Conversion and Array Processing and more Assignments Computer Science in PDF only on Docsity!

CS 061 โ€“ Computer Org. & Assembly Lang. Fall - 2003

Assignment 6 โ€“ due Wednesday 11/19, 11 pm (secure server turnin)

  1. Re-write your decimal to binary conversion program as a subroutine. The main routine should ask the user to input a decimal integer in the range 0 to 32,767, and pass to the subroutine a) the address of the start of the ASCII array, and b) the number of digits stored in the array, which must be <= 5. The subroutine will process the array, and return the corresponding binary value in a register.
  2. Now expand this program to ask the user to input 10 integers (0 to 32,767), and build an array of the corresponding binary numbers. e.g. (using 5 numbers instead of 10): the user inputs the numbers: 7 15 2 25 0 the end result is an array, starting at address (say) x3400: 0000 0000 0000 0111 0000 0000 0000 1111 0000 0000 0000 0010 0000 0000 0001 1001 0000 0000 0000 0000
  3. Now add 100 to each of the numbers in the array, and output the new values as decimal numbers (ii.e.as ASCII characters). Your binary to decimal conversion should also be written as a subroutine which takes a single 16-bit binary number in a register, and returns a) the address of the start of the ASCII array, and b) the number of digits stored in the array, which must be <= 5. (in other words, exactly the inverse of the decimal to binary subroutien in 1). So the output from the above example would be: 107 115 102

ERROR CHECKING:

As always, test the input for invalid characters; note that the characters โ€˜#โ€™ (indicating a decimal number) and โ€˜+โ€™ are valid but not required, as are leading โ€˜0โ€™s; you should allow these characters and then disregard them: this should all be already built into your conversion subroutines. The one new test you will have to do is see if the addition of 100 to an element of the array causes an overflow: if the result appears negative, set the number to zero. BONUS: For an extra 2 points , allow the user to enter as many numbers as desired, terminating the input with the symbol * (or in any way you think appropriate).

Grading policy:

Possible points: 10

Program assembles without errors: 3

Program runs correctly on LC-3 simulator 5

Well commented code: 2

Assignment submitted without name and SSN:-5 points (if we can figure out who you are!)