SN2019 Exam: Answers. Q1
(a) (i) 180 = 10110100 = $B4 Any suitable arithmetic method for conversion from base 10 to 2 and then to hex, or directly from base 10 to base 16 [2]
(ii) 30 is 00011110 so -30 is 11100010 = $E2 Taught method requires use of algorithm to invert a twos¡¯ comp number by taking one¡¯s comp and adding 1. Any other successful arithmetic argument is also acceptable [2]
(b) The numbers that can be represented are from -2-31 to +231-1 Argument requires knowledge of general domain of n- bit two¡¯s complement code [2].
(c) Many options for X and Y. E.g. X=11111111 and Y = 00000001. In unsigned code this is 255 and 1 but in two¡¯s complement it is -1 and 1.
For W and Z , e.g. W=1000 0000 and Z=1000001 overflow in both codes. In unsigned code W is 128 and Z is 129; in two¡¯s complement W is -128 and Z is -127.
(d) Outline solution…
;for (i=0; i
; x[i]=x[i]-1 ;}
;}
; Register usage …
… ;
ADD LOAD LEA
;
Loop CMPEQ
JUMPF
LOAD
CMPEQ
JUMPT
SUB
STORE
ADD
JUMP
End TRAP
N DATA X DATA
…
R1,R0,R0
R2,N[R0]
R3,1[R0]
R15,R1,R2
R15,End[R0]
R5,X[R4]
R14,R5,R0
R14,SKIP[R0]
R5,R5,R3
R5,X[R4]
R1,R1,R3
Loop[R0]
R0,R0,R0
…
;i=0 ;R2=N ;R3=1
; If i