CS241 Lecture Notes - Lecture 6: Horse Length, Noam Chomsky, Formal Language

127 views5 pages
May 17, 2018
Last time:
- Creating a Symbol Table
0 main: lis $2 // 0 is the address
4 .word 13
8 lis $1
12 .word -1
16 add $3, $0, $0
loop:
; you can have multiple labels on the same line
20 begin: top: add $3, $3, $2
24 add $2, $2, $1
38 bne $2, $0, loop
32 end: jr $31
Symbol Table would look something like...
main -> 0
loop -> 20 // loop points to instruction that comes after it
begin -> 20
top -> 20
end -> 32
Recall:
add $3, $2, $4
000000 sssss ttttt ddddd 00000 100000
0 << 26 // left shift 26 times
000000 0...0 0...0 0...0 0...0 0...0
00010 << 21 // 2
0...0 00010 0...0 0...0 0...0 0...0
00100 << 16 // 4
0...0 0...0 00100 0...0 0...0 0...0
00011 << 11 // 3
0...0 0...0 0...0 00011 0...0 0...0
1000000 // 32
0...0 0...0 0...0 0...0 0...0 100000
Notice there's no overlap
000000 00010 00100 00011 00000 100000
Doing the above steps in one line, we get
int instr = 0 << 26 | 2 << 21 | 4 << 16 | 3 << 11 | 32;
Now, need to output that instr variable...
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
If we do cout << instr, then you'll get a decimal value
Instead, notice
int x = 65;
char c = 65;
cout << x << c;
Output: 65A
So separate bits into chunks of 8bits (4 bytes)
000000 00|010 00100| 00011 0000|0 100000|
int insrt = 0 << 26 | 2 << 21 | 4 << 16 | 3 << 11 | 32;
char c = instr >> 24 // place the first 8 bits all the way to the end
cout << c;
c = instr >> 16;
cout << c;
c = instr >> 8;
cout << c;
c = instr;
cout << c;
**outputting a character will read the last 8 bits so we shift so that the bits you're interested in
are at the end**
beq $1, $2, -3
000100 sssss ttttt iiiiiiii iiiiiiii (format)
4 << 26
000100 0...0 0...0 0...0 0...0 0...0
1 << 21
0...0 00001 0...0 0...0 0...0 0...0
2 << 16
0...0 0...0 00010 0...0 0...0 0...0
-3 (in two's complement)
1...1 11111101 // all leading 1's
Now there is overlap! Here's how to fix that...
-3 & 0xffff
1...1 11111111 11111101
&0...0 11111111 11111111
-----------------------
0...0 11111111 11111101
**end of assignment 3 material**
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

0 main: lis // 0 is the address. ; you can have multiple labels on the same line. Symbol table would look something like main -> 0 loop -> 20 // loop points to instruction that comes after it begin -> 20 top -> 20 end -> 32. 0 << 26 // left shift 26 times. Doing the above steps in one line, we get int instr = 0 << 26 | 2 << 21 | 4 << 16 | 3 << 11 | 32; If we do cout << instr, then you"ll get a decimal value. Instead, notice int x = 65; char c = 65; cout << x << c; So separate bits into chunks of 8bits (4 bytes) **outputting a character will read the last 8 bits so we shift so that the bits you"re interested in are at the end** beq , , -3. Recognition: done by the assembler (is the program valid)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents