2023/05/16 - 12:10
ASM went into the assembler, and it produces two files:
- lis
→ contains the translation of the input file
→ contains the symbol table.
- xme
→ contains S records.
→ 10 possible S records, 0-9
→ we are interested in 0, 1, 9
→ 0: header
⇒ contains name of the input file
⇒ read it in as %2x and display as %c
→ 1: data or instructions
→
→ 9: starting address
⇒ program counter
→ S# [length 2by] [addr 4by] [DATA (~30 bytes)] [checksum 2by]
⇒ checksum contains one's complement of the sum of the bytes.
⇒ sum of each byte from Len to itself.
⇒ should should get 0xFF (-1). if you get that number you can consider it a valid record.
⇒ loader should be able to test for invalid records.
⇒ S9 03 1000 EC → 03 + 10 + 00 + EC = -1
→ When we read in the address as individual bytes, we have split it in half. to recombine it to two bytes, we can shift the higher byte left by 8 and or the lower half.
→ read the bytes in as unsigned int and then mask them
→ we want to load all the bytes into contiguous memory starting from the indicated position.
→ remember the memory is little endian. the lower byte is stored first.
- Once the loader puts this into memory, what do we have?
→ We have our memory that goes from 0x0000 to 0xFFFF
→ The machine has to go through cycles of fetch, decode, execute.
→ Fetch: fetches the next instruction from memory.
⇒ Fetch will access the memory through the memory address / memory data register
⇒ It will need the program counter (PC)
• Where does it start?
• the default start should be 0
• If the program has to start at a specific location, it should be specified in the S9 record. The PC should be initialized to the value in the S9
⇒ Fetch from Mem[PC]
⇒ instruction is read into the MDR (memory data register)
⇒ Stored into the instruction register.
⇒ Interally we should see
• MDR ← Mem[PC]
• IR ← MDR
• PC ← PC + 2 (instruction size)
→ Decode:
⇒ Have the instruction in the IR
⇒ it is 16 bits long.
⇒ Decode it based on the instruction set.
• if we look at the first two bits, it can indicate that the instruction is a branch
• if we look at the most significant 3 bits, we can separate the group further.
• group the opcodes based on simiilar processing
• find patterns in the opcodes.
Forward references:
- if the assembler comes to a label that is defined later, and it doesnt exist yet in the symbol table, it will have to do another pass once the symbol is resolved. It will not raise an error.
Virtual Memory
- program is divided into pages, and physical memory isnt large enough to fit the entire program. So only pages are loaded into primary memory at a time. The rest is stored in secondary memory.
- If you stay within a loop on the page in memory, it wont get kicked out. But if the program execution goes beyond the page, it has to pull in the next one.
- A program could be n pages long, but you only have one page in memory at a time.
- When something outside the page is referenced, the next one is pulled in.
- The physical memory may store the pages in different locations, but the virtual memory would be contigious. Index