Data representation How do we represent data in



















- Slides: 19
Data representation How do we represent data in a digital system? Digital data is stored as bits: – a bit is a binary number {0, 1} – in a hardware design this is usually interpreted as 0 Volt, GND {5, 3. 3, 1. 8, … } Volt, VCC Computer Engineering Instr. Data. Format page 1
String of bits! Everything we work with is represented as a string of bits. Example: – We don't work with integers! – We represent (encode) integers as strings of bits and manipulate those. 1 0 1*23 + 0*22 + 1*21 + 0*20 8 +0 +2 +0 (binary) represents (decimal) = 10 (decimal) Computer Engineering Instr. Data. Format page 2
Ask yourself: How many bits are required to represent this thing? How can we do it? – We need to structure the information. Computer Engineering Instr. Data. Format page 3
Word, halfword and byte “The word: 32 bits”. 31 0 High order bit Low order bit “The halfword: 16 bits”. 0 15 “The byte: 8 bits”. 7 0 Computer Engineering Instr. Data. Format page 4
“The Space” We can group a large number of bit strings into an array called a space. We use at least three spaces: – the register space. – the instruction space. – the data space. Do not confuse them! Computer Engineering Instr. Data. Format page 5
The Register Space (or Register “file”) An array of words. Smallest addressable unit is the word. 32 choices, how do we select? – 2 x = 32, x? – x=5 – i. e. , we need 5 bits! 0 1 2 3 29 30 31 Computer Engineering Instr. Data. Format page 6
Address To work with a space we must be able to address the elements of the space. Each space may have a different address method. Computer Engineering Instr. Data. Format page 7
The Instruction space (or instruction memory) An array of bytes. Smallest addressable unit is a byte, but the smallest accessible unit is a word. 232 bytes gives 230 accessible words. Computer Engineering Instr. Data. Format page 8
What's that mean? An instruction address is 32 bits long. Same as a word. An instruction address fits into a word! Computer Engineering Instr. Data. Format page 9
But: Only every fourth address is legal. The ones whose last two bits are “ 00”. We can access 230 instructions. Computer Engineering Instr. Data. Format page 10
Instruction memory 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Address “ 4”: 0000. . . . 00100 Hardware accesses an entire 32 -bit word. Computer Engineering Instr. Data. Format page 11
Instruction memory 2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Address "3": The hardware will complain! This is called an “alignment error”. The address was not “word aligned”. 0000. . . . 00011 Computer Engineering Instr. Data. Format page 12
Byte order Big endian Little endian Byte 0 Byte 1 Byte 2 Byte 3 Addr 0 Addr 1 Addr 2 Addr 3 Byte 2 Byte 1 Byte 0 Addr 1 Addr 2 Addr 3 Computer Engineering Instr. Data. Format page 13
Instruction memory 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 An instruction is represented by 32 bits. There are two “instruction formats”. (Not the whole truth, but don't worry about it) Computer Engineering Instr. Data. Format page 14
Instruction formats Format 1 (reg) Format 2 (imm) 6 bits 5 5 5 Opcode rs rt rd 6 bits 5 5 16 Opcode rs rt Immediate Remember: – Never immediate field together with rd-field. – Immediate field is only 16 bits! Computer Engineering Instr. Data. Format page 15
“Data space” 232 bytes, byte addressable, byte accessible. A data address fits into 32 bits. Halfword accesses must be halfword aligned; (low order bit = 0). Word accesses must be word aligned; (low order 2 bits = 0). Computer Engineering Instr. Data. Format page 16
Review - How many bits? ? Instruction address Instruction – Immediate field – Register address Register Data address Data ? ? ? ? Computer Engineering Instr. Data. Format page 17
Review - How many bits? ? Instruction address Instruction – Immediate field – Register address Register Data address Data 32, 32 16 5 32 32, 8 16 32 word aligned byte aligned (byte) (halfword) (word) Computer Engineering Instr. Data. Format page 18
Questions? Feedback from the lectures: Per. Lindgren@ltu. se Computer Engineering Instr. Data. Format page 19