Homework 3 - Solutions

EECE 417


Program SOLUTION

Homework 3 ASM File

Purpose

This program is intended to provide experience in dealing with the computer's variety of data representations.

Program Statement

Write a SASM program that reads in a single positive integer, and prints it back out in hexadecimal.

A sample execution of the program looks like

 
Enter an integer (>0): 26
The value in hexadecimal: 1a
 

Requirements

  1. Your program must contain adequate comments (documentation). Such comments include your name and section number at the top of the program. They also include a description of the program, as well as variable descriptions and comments about the code itself.
  2. For this program, an integer consists of only the characters '0'-'9', and is immediately followed by the newline character (0ah). Any other input is considered bad. For the case of bad input, your program should print out an error message indicating bad input and then exit. Note that leading zeros must be handled correctly, since they are included (by this definition) as good input.

Handing In the Program

For this program, you will need to turn in your source code (the .asm extension) and your makefile (the .mak extension). No printout will be turned in.  These files must also be turned in on a disk, or send via email to the instructor.  I wil execute the program to determine if it is correct, so be sure to test your programs extensively.


Homework (25 points)

    1. (4 points)


(a) Convert the base 6 value 204 to base 4.

����� 204 base 6 =� (2*6^2) + (4 * 6^0) = 72 + 4 = 76 base 10

������ 76 base 10 = ? base 4

������� 76 / 4 =� 19 R 0

�������� 19 / 4 =�� 4 R 3

����������� 4/4 =��� 1 R 0

����������� 1/4 =���� 0 R 1

������ 76 base 10 = 1030 base 4

������ Therefore 204 base 6 = 1030 base 4

�
(b) Convert the base 4 value 310021.201 to base 2 (binary). �1 base 4 digit = 2 base 2 digits since 2^2 = 4
����������� 3��������� 1��������� 0��������� 0��������� 2��������� 1.�������� 2��������� 0��������� 1

��� ������� 11������� 01������� 00������� 00������� 10������� 01.������ 10������� 00������� 01

����������� 110100001001.100001

 

(c) Convert the base 8 value 615.201 to base 16 (hexadecimal). �1 base 8 digit = 3 base 2 digits

����������� 6��������� 1��������� 5.�������� 2��������� 0��������� 1

����������� 110����� 001����� 101.���� 010����� 000����� 001�����

110001101.010000001���������������������������������������������� �� 4 base 2 digits = 1 base 16 digit

1��������� 1000��� 1101.�� 0100��� 0000��� 1

0001��� 1000��� 1101.�� 0100��� 0000��� 1000

1��������� 8��������� D.������� 4��������� 0��������� 8

18D.408

(d) Convert the base 2 value 11001101 to base 10 (decimal).

(1 * 2^7) + ( 1 * 2^6) + (1 * 2^3) + (1*2^2) + (1 * 2^0) =

128 + 64 + 8 + 4+1 =� 205 base 10

    1. (9 points)


Give 8-bit representations to fill in the following table.

decimal     sign magnitude     two's complement     biased-127
 
  13������ 00001101�������������� 00001101������ �� 10001100
 
  -2������ 10000010�������������� 11111110������ �� 01111101
 
  185����� not possible�� ������� not possible�� �� not possible
    1. (4 points)


What string is represented by the SASM declaration

 
a_str  dd 52656164h
       dd 79210000h
 
�� 52����� 65����� 61����� 64
�� R������ e������ a������ d
 
�� 79����� 21����� 00����� 00
�� y������ !������ null��� null
Ready!
    1. (5 points)


What is the IEEE single precision floating point representation for the decimal number -22.25? Give the result in binary and in hexadecimal.

22.25 = 10110.01 = 1.011001 x 2 ^ 4

Sign = 1

Exp = 4 + 127 = 131 = 10000011

Mantissa = 01100100000000000000000

1��������� 10000011������� 01100100000000000000000

11000001101100100000000000000000

1100��� 0001��� 1011��� 0010��� 0000��� 0000��� 0000��� 0000

C�������� 1��������� B��������� 2��������� 0��������� 0��������� 0��������� 0

C1B20000

 

    1. (3 points)


What decimal value is represented by the IEEE single precision representation, given in hexadecimal by 0xc4800000?

C�������� 4��������� 8��������� 0��������� 0��������� 0��������� 0��������� 0

1100��� 0100��� 1000��� 0000��� 0000��� 0000��� 0000��� 0000

1��������� 10001001������� 000����� 0000��� 0000��� 0000��� 0000��� 0000

sign = 1

exp = 128 + 9 = 137 ; 137-127 = 10

mantissa = 1.00000000000000000000000

-1.0 x 2^10 = -1024.0

Handing In the Homework

For this homework, you will need to turn in a single file containing your answers to the homework questions. To make grading easier, please name your file hw1.group.X.txt. No printout will be turned in.