Mitglied der Zürcher Fachhochschule TIn 1: Lecture 3 The Belly of the Architect. Lecture 3: Lernziele Basic internal components of the 8086 Pointers and data storage in memory
Architektur 8086 Besteht aus Bus Interface Unit und Execution Unit Execution Unit Register ALU Flags Control Unit Bus Interface Unit Segment Register / Instruction Pointer Control Unit Instruction Queue Instruction Pointer What isan Instruction Pointer? Q: What is a pointer? Something that caused your blue-screen Java 101 Passing values by reference Lets look at passing by reference in C
Passing by reference x = swap(a,b) How can you get the result of a swap operation? array[1] = a; array[2] = b; x = swap(address_of_array, index_1, index_2) Lets look at arrays! array[0] = H ; array[1] = e ; array[2] = l array = H e l x x x x Adressen [))))) [))))) [))))) LW EUHLWHV0HPRU\ LW EUHLWHV0HPRU\
Adressen 8-Bit Zugriff Adress-Zeiger = 0x000000 Data = 0x48 Adress-Zeiger = 0x000001 Data = 0x65 Adress-Zeiger = 0x000002 Data = 0x6c Adress-Zeiger = 0x000003 Data = 0x6c
16-Bit Zugriff Adress-Zeiger = 0x000000 Data = 0x6548 Adress-Zeiger = 0x000002 Data = 0x6c6c Adress-Zeiger = 0x000004 Data = 0x??6f Muss das so sein? 16-Bit Zugriff und Address Boundaries Adress-Zähler = 0x000001 Data = 0x6c65 [))))) [))))) Nachteil? 2 Buszugriffe nötig Optimierungsmöglichkeit durch variable Positionierung auf gleichen Speicher-Adressen. F I F
Endian Unterschiede 16-bit Variablen können unterschiedlich gespeichert werden Intel = Little Endian Architektur Fazit Ein Zeiger zeigt auf Informationen und kann inkrementiert werden um auf die nächste Information zu zeigen Ein Zeiger wird um 1 inkrementiert um den nächsten Byte zu lesen, um 2 um den nächsten Wort (16-bit) zu lesen um 4 um den nächsten Longword (32-bit) zu lesen etc. Es gibt, für 16-bit Werte, zwei Speicherungs Möglichkeiten, für 32-bit Werte wie viele? Ein Address Zeiger kennen wir jetzt und zwar den Instruktion- Pointer. Mit dieser lässt sich aber nur Kode und Konstanten lesen.
Passing by reference X = swap(address_of_a, address_of_b); instead of X= sway(address_of_array, offset_a, offset_b); Why the bit about arrays? Because the relationship between pointers and arrays is very tight. What next? We will look at pointers in Assembler Then we will look at memory addressing and segmentation Then we will look further at command abstraction.
Mitglied der Zürcher Fachhochschule TIn 1: Lecture 4 Geiz ist nicht Geil! Lecture 3: Lernziele How the 8086 actually accesses memory What segmentation means Moving data in and out of memory
Memory addressing Immediate AND AL, 050H Implizit POP AX Register Direkt AND AL, AH IN AL, 020H OR DX, Byte_Array Register Indirect XOR AX, [DX] Pointers A pointer = memory indirect XOR AX, [DX] The content of the address which is in DX is XOR ed with the contents of AX. So if AX = 05H and DX = 0001H what is in AX after the operation XOR AL, [DX]?
What next? Easy oder? Hmmm.. How big is the DX register? What isthe address range of the 8086? Does it fit? What next? I don t think so. To save costs Intel decided to reduce the complexity of the architecture by allowing only 16 bit addresses internally = 64K Since the hardware has a 1MB address range another register is needed to store the upper 4 bits of the address This makes the Intel architecture a joy to work with
Consequences Memory is segmented The programmer has to KNOW in which segment he is currently operating in. Why? Because if code = read-only and data is read-write then two different segments are needed for data and code. AND the programmer must know where in the segment he is operating. Why? Because you can t place arrays in memory that crosses a segment that cross a segment The programmer has to SWITCH between segments Consequences Where are the segments stored in the CPU? Picture: Abb. 7.5 How is the memory segmented? Picture: Abb. 7.8 How does the CPU translate between the segment registers and the address register to generate the physical address? Picture: Abb. 7.6 and Abb.7.7
Discussion Questions What happens if there are more segments than physical memory? How large can a programm be if the code segment and the data segment are the same? How large is the I/O address range? Mitglied der Zürcher Fachhochschule TIn 1: Back to memory
Remember when We said that every Java operation has a direct equivalent Assembler command? Path from Java Application to? Java C/C++ Assembler Machine Code Hardware &,, ^, ~ +, -, *, / &,, ^, ~ +, -, *, / AND, OR, XOR, NOT ADD, SUB, MUL, DIV 20H-25H, 08H-0DH, 30H-35H, 5FH 00H.15H Gates: and, or, xor, not Full/half adder, subtractor >>, >>>, << >>, << SHR, SAR, SHL, SAL Shift registers
Remember when We said that every Java operation has a direct equivalent Assembler command? And that the assembler provides a first layer of abstraction from machine code. But we also said that there is a JNZ command, which is dependent on what? Which means that Java provides an abstraction from this operation. What else? Suppose byte a = 02, b = 03, c= 0; c = a & b; Translates into AND AL, BL What step is missing? Initalising AL and BL Filling CL with the result
How does this code translate? Therefore byte a = 02, b = 03, c= 0; c = a & b; Translates into MOV AL, 02H MOV BL, 03H MOV CL, 00H AND AL, BL MOV CL, AL And what is missing? How does this code translate? Translates into MOV AL, 02H MOV BL, 03H MOV CL, 00H AND AL, BL MOV CL, AL And what can be optimised?
Exercise? Translate short a = 300; byte b = 05, c=0; c = a & b; What does the compiler do for us automatically? String Ausgabe V1.0 ; --- Define String Hello DB 048H, 065H, 06cH, 06cH, 06fH, ; --- Hello DB 020H, ; --- DB 057H, 06fH, 072H, 06cH, 064H, ; --- World DB 00H, 13H ; ----- Print Hello World Print_Hello_World: MOV DX, Hello Printline: MOV AL, [DX] CALL Character_Out INC CMP JNZ DX [DX], 00H Printline
Questions What is the difference between the string Hello World in Java and in Assembler? In which segment is Hello stored? In which segment does the processor presume that Hello is stored? Will the loop ever end?