Assignment 7, Solutions
Part of
the homework for 22C:60 (CS:2630), Spring 2012
|
void upcase( char * src; char * dst ) { char ch; do { ch = *src; if ((ch >= 'a') && (ch <='z')) { ch = ch + ('A' - 'a'); } *dst = ch; src = src + 1; dst = dst + 1; } while (ch != NULL); }
UPCASE: ; expects R3 = src -- pointer to source string ; R4 = dst -- pointer to destination string ; uses R5 = ch -- one character being processed ; R6 = temp ; returns R3-6 with unpredictable contents UPLOOP: ; do { LOADS R5,R3 EXTB R5,R5,R3 ; ch = *src CMPI R5,'a' BLT UPENDF CMPI R5,'z' BGT UPENDF ; if ((ch>='a')&&(ch<='z')) { ADDI R5,R5,'A'-'a' ; ch = ch + ('a' - 'A') UPENDF: ; } LOADS R6,R4 STUFFB R6,R5,R4 STORES R6,R4 ; *dst = ch; ADDSI R3,1 ; src = src + 1; ADDSI R4,1 ; dst = dst + 1; TESTR R5 BZR UPLOOP ; } while (ch != NULL) JUMPS R1
A Problem: Write an equivalent SMAL Hawk subroutine that takes R3 as the source address and R4 as the destination address, and conforms to the standard Hawk calling sequence. (1.0 points)
a) ... it uses explicit inverters instead of bubbles on inputs to gates. (0.4 points)
b) ... so that, as a result of applying De Morgan's laws, it only uses nand gates and does not use any and or or gates. (0.4 points)
Note: Neatness counts. Graph paper, rulers and other tools can all help.
A problem: Give the truth table for a one-bit stage of a subtractor. (0.8 points)
Note: You may find that the discussion of an adder-subtractor in the section of Chapter 8 on arithmetic logic units provides useful insight.
si mi bi di bi+1 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1