150 likes | 304 Views
v on Neumann model. The model defines a computer as four subsystems: memory, arithmetic logic unit, control unit, and I/O. The data and program are stored as binary patterns in memory. Sequential execution of instructions. ASCII Code.
E N D
von Neumann model The model defines a computer as four subsystems: memory, arithmetic logic unit, control unit, and I/O The data and program are stored as binary patterns in memory Sequential execution of instructions
ASCII Code 32 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 See Also: EBCDIC
One’s complement integers • Range: -(2N-1-1) … +(2N-1-1) # of Bits --------- 8 16 32 Range ------------------------------------------------------- -127 -0 -32767 -0 -2,147,483,647-0 +0 +127 +0 +32767 +0 +2,147,483,647 • Storing one’s complement integers process: • The number is changed to binary; the sign is ignored • 0s are added to the left of the number to make a total of N bits • If the sign is positive, no more action is needed. If the sign is negative, every bit is complemented.
Two’s complement integers • Range: -(2N-1) … +(2N-1-1) # of Bits --------- 8 16 32 Range ------------------------------------------------------- -128 -32,768 -2,147,483,648 0 +127 0 +32,767 0 +2,147,483,647 • Storing two’s complement integers process: • The number is changed to binary; the sign is ignored • If the number of bits is less than N, 0s are added to the left of the number so that there is a total of N bits. • If the sign is positive, no further action is needed. If the sign is negative, leave all the rightmost 0s and the first 1 unchanged. Complement the rest of the bits.
Summary of integer representation Unsigned ------------ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sign-and-Magnitude --------- +0 +1 +2 +3 +4 +5 +6 +7 -0 -1 -2 -3 -4 -5 -6 -7 One’sComplement --------- +0 +1 +2 +3 +4 +5 +6 +7 -7 -6 -5 -4 -3 -2 -1 -0 Two’sComplement -------- +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1 Contents of Memory------------ 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Example 17 Transform the fraction 0.875 to binary Solution Write the fraction at the left corner. Multiply the number continuously by 2 and extract the integer part as the binary digit. Stop when the number is 0.0. 0.875 1.750 1.5 1.0 0.0 0 . 1 1 1
Example 21 Represent 81.5625 in IEEE standard Solution 8110 = 010100012 ; 0.5625 = 0.10012 1010001.1001 = + 26 x 1.0100011001 Exponent 6 is expressed in Excess_127 as 133 = 100001012 0 10000101 01000110010000000000000
Variable Types in BASIC • Numeric • CODE=67 • A=-5 • Pi=3.14159 • String • S$=“N” • School_name$=“National Chi Nan University”
^ * / MOD + - = (equality) <> (inequality) < > >= <= NOT AND OR XOR Operators
Condition • 140 REM --- Is this a leap year? • 150 IF Y MOD 4 = 0 THEN LEAP = 1 ELSE LEAP = 0 • 160 IF Y MOD 100 = 0 THEN LEAP = 0 • 170 IF Y MOD 400 = 0 THEN LEAP = 1
Loop • FOR … NEXT • DO WHILE
Sorting 20 REM Sorting 30 DATA 1, 3, 5, 7, 2, 4, 6 40 K=7 50 DIM A(K) 60 FOR I=1 TO K 70 READ A(I) 80 NEXT I 85 GOSUB 200 90 FOR I=1 TO K-1 100 FOR J=I+1 TO K 110 IF A(I) > A(J) THEN TEMP=A(I): A(I)=A(J): A(J)=TEMP 120 NEXT J 125 GOSUB 200 130 NEXT I 150 END 200 REM --- Print out the array --- 210 FOR H=1 TO K 220 PRINT A(H); 230 NEXT H 240 PRINT 250 RETURN