Rutgers University Santosh Nagarakatte 10 Assembly Programming Brief tour

Rutgers university santosh nagarakatte 10 assembly

This preview shows page 10 - 25 out of 155 pages.

Rutgers University Santosh Nagarakatte 10 Assembly Programming Brief tour through assembly language programming Why? n Machine interface: where software meets hardware n To understand how the hardware works, we have to understand the interface that it exports Why not binary language? n Much easier for humans to read and reason about n Major differences: l Human readable language instead of binary sequences l Relative instead of absolute addresses
Image of page 10
Assembly Programmer’s View Control Logic (OS code & data) Object Code Program Data Addresses Data Instructions Registers ALU CPU Memory Condition Codes PC
Image of page 11
Memory 00101100 10001000 11111111 01010101 00000000 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage Address Command: R/W Data CPU
Image of page 12
Memory Access: Read 00101100 10001000 11111111 01010101 00000000 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage 03 R CPU 01010101
Image of page 13
Memory Access: Write 00101100 10001000 11111111 01010101 00000000 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage 04 W CPU 01010101
Image of page 14
Memory Access: Write 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage 04 W CPU 01010101
Image of page 15
Processor: ALU & Registers ALU B C A S C = F S (A, B) F includes Arithmetic: +, -, *, /, ~, etc. Logical: <, >, =, etc. 00101100 10001000 11111111 01010101 R0 R1 R2 R3 Name Storage Registers Name Command: R/W Data Multiple Ports
Image of page 16
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes
Image of page 17
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes 1
Image of page 18
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes 1 1 10001000
Image of page 19
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes 1 1 10001000 + R0 R1 R0: x R1: y
Image of page 20
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes 1 1 10001000 + R0 R1 x y R0: x R1: y
Image of page 21
Putting It All Together ALU Control Logic Registers Program Counter (PC) 00101100 10001000 11111111 01010101 01010101 11000001 00000000 11111001 11111000 00110000 00000000 00000000 00000000 11000011 00011001 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Memory Addresses Storage CPU Condition Codes 2 1 10001000 + R0 R1 x y z R2: z R0: x R1: y R2
Image of page 22
Rutgers University Santosh Nagarakatte 23 C & Assembly Code int accum; int sum(int x, int y) { int t = x + y; accum += t; return t; } gcc -O1 -m32 –S code.c Sample C Code sum: push %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax addl %eax, accum popl %ebp ret Generated Assembly
Image of page 23
Rutgers University Santosh Nagarakatte 24 C & Machine Code int accum; int sum(int x, int y){ int t = x + y; accum += t; return t; } gcc -O1 -m32 –c code.c Sample C Code (gdb) x/100xb sum gdb code.o <sum>: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x8 <sum+8>: 0x08 0x01 0x05 0x00 0x00 0x00 0x00 0x5d
Image of page 24
Image of page 25

You've reached the end of your free preview.

Want to read all 155 pages?

  • Fall '15
  • SantoshNagarakatte
  • Computer Architecture, Processor register, Call stack, Addressing mode, eax, Prof. Santosh Nagarakatte, Santosh Nagarakatte

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture