Unformatted text preview:

Slide 1Today: Machine Programming I: BasicsIntel x86 Processors, contd.Intel’s 64-BitSlide 11Our CoverageToday: Machine Programming I: BasicsDefinitionsAssembly Programmer’s ViewProgram to ProcessProcess in MemoryA shell forks and execs a calculatorA shell forks and then execs a calculatorAnatomy of an address spaceTurning C into Object CodeCompiling Into AssemblyAssembly Characteristics: Data TypesAssembly Characteristics: OperationsObject CodeDisassembling Object CodeAlternate DisassemblyWhat Can be Disassembled?Today: Machine Programming I: BasicsInteger Registers (IA32)Simple Memory Addressing ModesUsing Simple Addressing ModesUsing Simple Addressing ModesUnderstanding SwapUnderstanding SwapUnderstanding SwapUnderstanding SwapUnderstanding SwapUnderstanding SwapUnderstanding SwapUnderstanding SwapComplete Memory Addressing Modesx86-64 Integer RegistersMACHINE-LEVEL PROGRAMMING I: BASICSCOMPUTER ARCHITECTURE AND ORGANIZATION2University of Texas at Austin2Today: Machine Programming I: Basics•History of Intel processors and architectures•C, assembly, machine code•Assembly Basics: Registers, operands, move6University of Texas at Austin6Intel x86 Processors, contd.•Machine Evolution•386 19850.3M•Pentium 19933.1M•Pentium/MMX 19974.5M•PentiumPro 19956.5M•Pentium III 19998.2M•Pentium 4 200142M•Core 2 Duo 2006291M•Core i7 2008731M•Added Features•Instructions to support multimedia operations•Parallel operations on 1, 2, and 4-byte data, both integer & FP•Instructions to enable more efficient conditional operations•Linux/GCC Evolution•Two major steps: 1) support 32-bit 386. 2) support 64-bit x86-6410University of Texas at Austin10Intel’s 64-Bit•Intel Attempted Radical Shift from IA32 to IA64•Totally different architecture (Itanium)•Executes IA32 code only as legacy•Performance disappointing•AMD Stepped in with Evolutionary Solution•x86-64 (now called “AMD64”)•Intel Felt Obligated to Focus on IA64•Hard to admit mistake or that AMD is better•2004: Intel Announces EM64T extension to IA32•Extended Memory 64-bit Technology•Almost identical to x86-64!•All but low-end x86 processors support x86-64•But, lots of code still runs in 32-bit mode11University of Texas at Austin1112University of Texas at Austin12Our Coverage•IA32•The traditional x86•x86-64/EM64T•The emerging standard•Presentation•Book presents IA32 in Sections 3.1—3.12•Covers x86-64 in 3.1313University of Texas at Austin13Today: Machine Programming I: Basics•History of Intel processors and architectures•C, assembly, machine code•Assembly Basics: Registers, operands, move14University of Texas at Austin14Definitions•Architecture: (also instruction set architecture: ISA) The parts of a processor design that one needs to understand to write assembly code. •Examples: instruction set specification, registers.•Microarchitecture: Implementation of the architecture.•Examples: cache sizes and core frequency.•Example ISAs (Intel): x86, IA, IPF15University of Texas at Austin15CPUAssembly Programmer’s View•Programmer-Visible State•PC: Program counter•Address of next instruction•Called “EIP” (IA32) or “RIP” (x86-64)•Register file•Heavily used program data•Condition codes•Store status information about most recent arithmetic operation•Used for conditional branching•Memory•Byte addressable array•Code, user data, (some) OS data•Includes stack used to support proceduresPCRegistersMemoryObject CodeProgram DataOS DataAddressesDataInstructionsStackConditionCodes16University of Texas at Austin16Program to Process•We write a program in e.g., C.•A compiler turns that program into an instruction list.•The CPU interprets the instruction list (which is more a graph of basic blocks).void X (int b) { if(b == 1) {…int main() { int a = 2; X(a);}17University of Texas at Austin17Process in Memory•Program to process.void X (int b) { if(b == 1) {…int main() { int a = 2; X(a);}What you wroteWhat is in memory.void X (int b) { if(b == 1) {…int main() { int a = 2; X(a);}Codemain; a = 2X; b = 2HeapStackWhat must the OS track for a process?18University of Texas at Austin18pid = 127open files = “.history”last_cpu = 0pid = 128open files = “.history”last_cpu = 0A shell forks and execs a calculatorint pid = fork();if(pid == 0) { close(“.history”); exec(“/bin/calc”);} else { wait(pid);int pid = fork();if(pid == 0) { close(“.history”); exec(“/bin/calc”);} else { wait(pid);Process ControlBlocks (PCBs)OSUSERint pid = fork();if(pid == 0) { close(“.history”); exec(“/bin/calc”);} else { wait(pid);int calc_main(){ int q = 7; do_init(); ln = get_input(); exec_in(ln);pid = 128open files = last_cpu = 0int pid = fork();if(pid == 0) { close(“.history”); exec(“/bin/calc”);} else { wait(pid);19University of Texas at Austin19pid = 127open files = “.history”last_cpu = 0pid = 128open files = “.history”last_cpu = 0A shell forks and then execs a calculatorint shell_main() { int a = 2; …Codemain; a = 2HeapStack0xFC0933CAint shell_main() { int a = 2; …Codemain; a = 2HeapStack0xFC0933CAint calc_main() { int q = 7; …CodeHeapStack0x43178050pid = 128open files =last_cpu = 0Process ControlBlocks (PCBs)OSUSER20University of Texas at Austin20Anatomy of an address spaceCodeHeaderInitialized dataExecutable FileCodeInitialized dataHeapStackDLL’smapped segmentsProcess’s address spaceInaccessible21University of Texas at Austin21texttextbinarybinaryCompiler (gcc -S)Assembler (gcc or as)Linker (gcc or ld)C program (p1.c p2.c)Asm program (p1.s p2.s)Object program (p1.o p2.o)Executable program (p)Static libraries (.a)Turning C into Object Code•Code in files p1.c p2.c•Compile with command: gcc –O1 p1.c p2.c -o p•Use basic optimizations (-O1)•Put resulting binary in file p22University of Texas at Austin22Compiling Into AssemblyC Codeint sum(int x, int y){ int t = x+y; return t;}Generated IA32 Assemblysum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax popl %ebp retObtain with command/usr/local/bin/gcc –O1 -S code.cProduces file code.sSome compilers use instruction “leave”23University of Texas at Austin23Assembly Characteristics: Data Types•“Integer” data of 1, 2, or 4 bytes•Data values•Addresses (untyped pointers)•Floating point data of 4, 8, or 10 bytes•No aggregate types such as arrays or structures•Just contiguously


View Full Document

UT CS 429H - Machine level programming I- Basics

Download Machine level programming I- Basics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Machine level programming I- Basics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Machine level programming I- Basics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?