Computer Science Lectures/Introduction to Computer Systems - CMU

Lecture 05: Machine-Level Programming 1: Basics

오렌지색 귤 2022. 10. 19. 23:48
반응형

History of Intel processors and architectures

 

Intel x86 Processors

Complex instruction set computer (CISC)

  • Many different instructions with many different formats
  • Hard to match performance of Reduced Instruction Set Computers (RISC)

 

2015 State of the Art

Core i7 Broadwell 2015

  • DDR : DRAM (메인 메모리)로 이어진다
  • PCI : Peripheral Devices로 이어진다
  • SATA : 여러 디스크로 이어진다
  • Ethernet : 네트워크로 이어진다

 

 

Our Coverage

IA32

  • The traditional x86

x86-64

  • The standard
gcc hello.c
gcc -m64 hello.c

 

 

 

C, assembly, machine code

 

Definitions

Architecture (ISA) : The parts of a processor design that one needs to understand or write assembly/machine code

  • Examples : instruction set specification, registers

Microarchitecture : Implementation of the architecture

  • Examples : cache sizes and core frequency

Machine Code : The byte-level programs that a processor executes

Assemly Code : A text representation of machine code

 

 

 

Assembly/Machine Code View

 

 

Turning C into Object Code

 

 

Compiling Into Assembly

Shark machine이 아니면 전혀 다른 결과가 나올 수 있다

 

 

Assembly Characteristics: Data Types

 

 

Assembly Characteristics: Operations

 

 

Machine Instruction Example

Assembly code 레벨에서는 변수명 등은 전혀 알 수 없다

 

 

 

Disassembling Object Code

objdump를 통해 볼 수 있는 코드

 

 

Alternate Disassembly

gdb를 통해 볼 수 있는 코드

 

 

Assembly Basics: Registers, operands, move

 

x86-64 Integer Registers

%r으로 시작하면 64bit, %e로 시작하면 32bit

  • rsp : stack

 

 

Some History: IA32 Registers

16bit, 8bit도 과거에는 존재했다

  • esp : stack pointer
  • ebp : base pointer

 

 

Moving Data

 

 

movq Operand Combinations

 

 

Simple Memory Addressing Modes

 

Example of Simple Addressing Modes

%rdi는 첫번쨰 인수, %rsi는 두번째 인수를 받는 레지스터

 

 

Complete Memory Addressing Modes

배열 주소에서 사용되는 방식

 

 

 

Address Computation Examples

 

 

Arithmetic & logical operations

 

Address Computation Instruction

3배 해주고 2배 해주는 방식으로 컴파일

 

 

Some Arithmetic Operations

Src는 앞, Dest는 뒤라는 것을 알아두자

 

 

Arithmetic Expression Example

 

 

 

Summary

 

반응형