What is the general purpose register

6 MMIX processor. 6.1 programming model. P.219 everything is important. 6.2 Register. General purpose register

Transcript

1 6 MMIX processor model of a processor (no legacy effects) Register-register architecture with 256 general purpose registers and 32 special registers Word length of the registers, the arithmetic unit, the data and address buses: 64-bit instruction set of 256 commands each 32-bit length The address area of ​​the virtual main memory comprises 2 64-byte execution time of the most commands 1 clock Ox Byte 6.1 programming model IT p.219 everything important 6.2 registers general purpose registers To store data have no special function 256 pieces numbered from $ 0 to $ 255 there are global, marginal and local registers special register rg contains the number of the first occupied global Registers, rl contains the number of the first free local register O 1 = u

2 special registers The MMIX processor has 32 special registers: ra, rb to rz and additionally rbb, rtt, rww, rxx, ryy, rzz Each special register has a specific use such as the configuration of the hardware, interrupts or the provision of hardware information (see ra as an example P. 221) 6.3 Memory Byte-addressed memory: the smallest addressable data element is one byte. Saving and loading is supported in word widths of 1 byte, 2 bytes (Wyde), 4 bytes (Tetra) and 8 bytes (Octa) Reading data from the memory there are some hardware-related limitations. To understand these limitations, let's look at how read access to a byte, Wyde, Tetra, Octa works (p.225): a oooo "". :: X Fontane : gtfo Yum That means, due to the hardware, we only get the data from the following memory chip combinations (0,1), (2,3), (4,5), (6,7) when reading out a Wydes. When reading out a tetra, we only get the data from the memory chip combinations (0,1,2,3) and (4,5,6,7). Since we want to get all the data through a load access, we allocate the wydes, tetras when saving and octas like this:

3 Big and Little Endian Two ways of storing data words that are larger than 1 byte The MMIX processor uses BigEndian I memory organization MMIX has an address width of 64 bits, i.e. bytes from 0x to 0xFFFF FFFF FFFF FFFF can be addressed. The memory is divided as follows:

4, E $ Text segment: Programs and interrupt vectors from memory address 0x100 contains MMIX programs, ie many 32 bit command words The exact start address of the program is specified in the symbol table of the object file * .mmo Computer with MMIX processor running in simulation. The object file contains the entire program in machine code, the command words, information about the pre-allocation of the memory and the symbol table The loader (part of the operating system) copies the program to be executed from the object file into the memory The symbol table consists of name, address pairs, so that entry addresses modules, functions and blocks can be found. Interrupts: program interruptions that occur during the execution (ie at runtime) of a program. E.g. division by zero, memory access error.

5 InterruptServiceRoutinen: Function / program that is called as soon as an interrupt occurs. The currently running program is stopped by the operating system in order to do the ISR first. Interrupt vectors: Contain the addresses of the executing ISR directly or indirectly or the interrupt vectors contain the ISR command words themselves. Some interrupts have their own interrupt vectors, other interrupts are combined in an interrupt vector. With the MMIX, the interrupt vectors already contain the ISRs. Data segment # = Contains global, static and data allocated at runtime that are stored on the heap from 0x on Contains local data that are created from address 0x3FFFFFFFFFFFFFFF towards addresses that are becoming smaller Pool segment Serves for communication between the operating system and the program. For example, transferring program call parameters Stack segment Irrelevant Operating system segment Contains the operating system Virtual memory The memory addresses that a program accesses do not correspond to the real physical memory addresses, but are fooled by the operating system into the program to be executed. Each program has its own working memory. The real memory allocation is taken care of by the operating system. For example a program can be fooled into having a 2 64 bit address space (several exabytes), although only 8 gigabytes of RAM are available. 6.4 MMIX programs MMIX programs are source text files that contain commands for the MMIX processor (instruction set of commands), for the loader (loads the program into the main memory) and for the assembler itself. When the program is executed, roughly the following things happen: 1. The assembler converts the source code into machine code (names must first be resolved) 2. Loader loads the machine code (as specified in the source code) into the main memory

6 3. The machine code in the text segment is executed by the processor. Syntax marker column: Optional except for Main. For naming memory locations. Serve the programmer as a programming aid. Command column: Contains the command for the processor, loader or assembler. Operand column: Most of the data to be processed. Comment column: Programming aid. For further syntax information: p.243 assembler and loader commands IS command: assembler command to make general purpose registers addressable by name. Name IS register The instruction tells the assembler that before translating the source text into machine code, it must first convert the names into the corresponding registers in the source code. GREG command (G for global, REG for register): Loader command. Reserves the next free global register (special register rg is reduced by 1) and initializes this register with the value given as a parameter. Name GREG value The LOC command: Loader command. LOC can be used to specify the address at which the loader is to start writing the command code for the processor (often LOC # 100 for command set commands and LOC DataSegment for variables defined before the start of the program)

7 LOC address BYTE, WYDE, TETRA, OCTA commands: Loader commands. The commands tell the loader that it should allocate memory for the current (indicated by LOC, usually in the DataSegment) and that it should also initialize it with the given parameter. The current address is automatically increased when using these commands. Name Command Value Translation process 1. You write a source file with a text editor and save it with the extension.mms 2. You use the command mmixal * .mms (in the terminal). The assembler resolves names and brands and creates a symbol table for the loader. Then the assembler translates your code into machine code, into a * .mmo file (an object file). 3. With the command mmix i * .mmo (in the terminal) you can have your program run by the processor in the simulator.

8 command words for the MMIX processor OP contain the OP code, i.e. what the processor should do with the data ADD, SUB, LDO, STO are OP codes X, Y, Z are either registers or direct operands (numbers). Y and Z are often source registers and X is the register where the result is written. MMIX opcodes machine code table

9 Translation of an opcode into the binary word: 1. Look in which line the binary word is to find the first 4 bits (eg SR [I] is in line 0x3) 2. Look whether the opcode is in the line above or below (eg SR [I] is in the lower line from 0x3 ..). If the opcode is in the line above, the nibble (4-bit binary word) written at the top of the table come into question. If the opcode is in the line below, the nibbles written in the table at the bottom are possible (eg SR [I] is in the lower half, therefore 0x ... C and 0x ... D are possible) 3. Opcodes with an [I] can be used with direct operands. If you choose the instruction with direct operands, use the right-hand ending, if not, use the left-hand ending. Opcodes with a [B] are commands with which there is a jump. In the case of a forward jump (to a larger address) the left-hand ending is used; in the case of a backward jump, the right-hand extension is used. ν, µ and π say something about the execution time of the command (more information p. 257) 6.5 MMIX commands

10 There are a lot of definitions on pages 260-263. What the definitions are for will become clear later in the exercises. Just read it once and look it up later if you don't understand it. For the following commands it is important that you can understand the description (see picture). It is an advantage if you know the most important commands by heart. Register / register commands MMIX commands for the processor in which the source operands Y, Z and the destination operand X are general-purpose registers. The register / register commands in the script are divided into: Arithmetic commands on fixed point numbers (ADD, SUB, NEG, MUL, DIV ..) Write direct operand in register (SETL, SET ..) Conversion of floating point numbers to fixed point numbers (FLOT, FIX ..) Arithmetic commands on floating point numbers (FADD, FSUB ..) Shift commands (SL, SLU, SR ..) Logical operations on bit level (AND, OR, XOR ..) Register memory commands Here it becomes clear why we often use the GREG command in programs to convert an address into to store a global register. The global register serves as a base register to load from the memory or to be able to write to the memory. Load data from the memory into a register (e.g. LDO, LDB) Write (save) data from the register into the memory (e.g. STB, STO) Load addresses into a register (LDA, GETA) Access to special registers (GET, PUT) In order to save special registers in To be able to load general purpose registers and to be able to write in special registers. Branch commands (JMP, BZ, BNN ..) To implement if, else statements in the program. Commands for function calls (GO) Namespaces of the PREFIX command

11 an assembler instruction is a programming aid. If you write a PREFIX << Name: >> command in front of your individual functions and end the namespace again with PREFIX: after your function, you do not need to worry when writing your individual functions that you accidentally use a name that is already used in another function used. Function calls What do we use functions for in programming? You can transfer various inputs a, b, c to a function that implements the midnight formula, for example, and the function calculates the appropriate output, the zeros. Better code structure! The code is more readable, you don't get confused so easily. Less code! Functions are often called more than once. Easier CodeMaintenance. Value transfer and reference transfer Definition: The function caller is nothing other than the function (e.g. Main) that calls the function under consideration.

12 In the case of value transfer (call by value), the value to be processed is transferred directly to the function, e.g. a fixed point number. When transferring reference (call by reference), the function is transferred the address of the value to be processed, e.g. the address at which a fixed point number is stored in memory. In both cases, a local copy is created when the parameters are passed. Calling Convention a Motivation What is a calling convention about? If you use a high-level language and call a function, that's easy. You don't care what the processor is doing exactly, you just write something like: result = function (param1, param2); Ultimately, however, this has to be converted into commands that the processor understands. On the following pages 308+, we use the MMIX processor to learn how a function call in machine language / assembler code can look. Imagine we are in the middle of the main function in the MMIX code and want to call a function that is stored at a different address in the memory. That means we use the GO command to jump to the function address and at the same time to get the return address. But how should the function caller (e.g. Main) pass the parameters of the function to be called? Best always in the same place in the memory. After all, the function stupidly always processes the same code and does not know anything about the function caller. And it must also be considered where the return values ​​are transferred. In order to regulate these things uniformly, each processor has an architecture-dependent calling convention. With the MMIX, parameters, return values ​​and local variables (the lower general-purpose registers) are transferred on the stack (# 3FFFFFFFFFFFFFF8 and smaller) For details see page 309 onwards