Assignment 2, due Jan 30Solutions
Part of
the homework for CS:2630, Spring 2015
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
a) 100 = 01100100
b) 120 = 01111000
c) 140 = 10001100
d) 160 = 10100000
e) 170 = 10101010
a) 01100100 = 100
b) 01111000 = 120
c) 10001100 = -116 *
d) 10100000 = -96 *
e) 10101010 = -86 *
a) 100 = 01100100
b) 120 = 01111000
c) -115 = 10001100 *
d) -95 = 10100000 *
e) -85 = 10101010 *
* Note added Feb. 20: In the above two problems, the originally posted answers were in error in the least significant bit.
a) 01100100 = 64
b) 01111000 = 78
c) 10001100 = 8C
d) 10100000 = A0
e) 10101010 = AA
14 ITEM1: W TEXT1 ; pointer to text 15 H 5 ; X = 5 16 H 1 ; Y = 1 17 18 ITEM2: W TEXT2 19 H 2, 1 ; an alternative compacted form 20 21 ITEM3:W SOMETEXT 22 H 2,2; don't write code like this, it works but it's hard to read 23 SOMETEXT:ASCII"world",0 24 25 TEXT1: ASCII "lo", 0 26 TEXT2: ASCII "Hel", 0
Lines 18-19 are in a style different from that of lines 14-16. Lines 21-23 are a deliberate example of horrible abuse of programming style.
A problem: Rewrite lines 18-26 so that the style is consistent with the style used in lines 14-17. Your code need not put data into memory in the same order as the original, but it should mean the same thing in the context of machine problem 1. Legible and neat handwritten work is acceptable on this assignment. (1 point)
In the following solution, I retained the line numbers from the original, where, for every line I changed, I added a suffix to the line number (A for the first line, B for the second, etc.)
14 ITEM1: W TEXT1 ; pointer to text 15 H 5 ; X = 5 16 H 1 ; Y = 1 17 18 ITEM2: W TEXT2 ; pointer to text 19A H 2 ; X = 2 19B H 1 ; Y = 1 20 21A ITEM3: W TEXT3 ; pointer to text 22A H 2 ; X = 2 22A H 2 ; Y = 2 24 25 TEXT1: ASCII "lo", 0 26 TEXT2: ASCII "Hel", 0 23A TEXT3: ASCII "world",0