Unformatted text preview:

Machine-Level Programming I: Basics Computer architecture and organizationToday: Machine Programming I: BasicsIntel x86 Processors, contd.Intel’s 64-BitOur 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 1985 0.3M• Pentium 1993 3.1M• Pentium/MMX 1997 4.5M• PentiumPro 1995 6.5M• Pentium III 1999 8.2M• Pentium 4 2001 42M• Core 2 Duo 2006 291M• Core i7 2008 731M• 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 Austin11Our 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.1312University of Texas at Austin12Today: Machine Programming I: Basics• History of Intel processors and architectures• C, assembly, machine code• Assembly Basics: Registers, operands, move13University of Texas at Austin13Definitions• 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, IPF14University of Texas at Austin14CPUAssembly 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 DataAddressesDataInstructionsStackConditionCodes15University of Texas at Austin15Program 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);}16University of Texas at Austin16Process 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?pid = 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);18University of Texas at Austin18pid = 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)OSUSER19University of Texas at Austin19Anatomy of an address spaceCodeHeaderInitialized dataExecutable FileCodeInitialized dataHeapStackDLL’smapped segmentsProcess’s address spaceInaccessible20University of Texas at Austin20texttextbinarybinaryCompiler (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 p21University of Texas at Austin21Compiling Into AssemblyC Codeint sum(int x, int y){int t = x+y;return t;}Generated IA32 Assemblysum:pushl %ebpmovl %esp,%ebpmovl 12(%ebp),%eaxaddl 8(%ebp),%eaxpopl %ebpretObtain with command/usr/local/bin/gcc –O1 -S code.cProduces file code.sSome compilers use instruction “leave”22University of Texas at Austin22Assembly 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

Download MACHINE LEVEL PROGRAMMING I
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 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 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?