reading assignment
play

Reading Assignment Chapter 3 (especially 3.1 to 3.9) (from - PowerPoint PPT Presentation

Reading Assignment Chapter 3 (especially 3.1 to 3.9) (from Computer System: A Programmers Perspec>ve, 2 nd Edi/on ) 1 Outline Introduc>on of


  1. Reading ¡Assignment ¡ • Chapter ¡3 ¡(especially ¡3.1 ¡to ¡3.9) ¡(from ¡ Computer ¡System: ¡A ¡Programmer’s ¡ Perspec>ve, ¡ 2 nd ¡Edi/on ) ¡ 1 ¡

  2. Outline ¡ • Introduc>on ¡of ¡IA32 ¡ • IA32 ¡opera>ons ¡ – Data ¡movement ¡opera>ons ¡ – Stack ¡opera>ons ¡and ¡func>on ¡calls ¡ – Arithme>c ¡and ¡logic ¡opera>ons ¡ – Compare ¡and ¡jump ¡opera>ons ¡ • Instruc>on ¡encoding ¡format ¡ • Array ¡and ¡structures ¡alloca>on ¡and ¡access ¡ 2 ¡

  3. RISC ¡instruc/on ¡sets ¡ 3 ¡

  4. CISC ¡instruc/on ¡sets ¡ 4 ¡

  5. RISC ¡and ¡CISC ¡(see ¡handout) ¡ • Which ¡is ¡IA32? ¡ ¡ – CISC ¡ • Which ¡is ¡Y86? ¡ ¡ – Includes ¡aNributes ¡of ¡both. ¡ ¡ – CISC ¡ • Condi>on ¡codes ¡ • Variable ¡length ¡instruc>ons ¡ • Stack ¡intensive ¡procedure ¡linkages ¡ – RISC ¡ • Load-­‑store ¡architecture ¡ • Regular ¡encoding ¡ • Which ¡is ¡beNer: ¡RISC ¡or ¡CISC? ¡ 5 ¡

  6. Compare ¡Y86 ¡and ¡IA32 ¡ • Y86 ¡is: ¡ – LiNle ¡endian ¡ – Load/store ¡ ¡ ¡ • Can ¡only ¡access ¡memory ¡on ¡read/write ¡ • On ¡move ¡statements ¡in ¡Y86 ¡(mrmovl/rmmovl) ¡ – Combina>on ¡of ¡CISC ¡and ¡RISC ¡ – Word ¡= ¡4 ¡bytes ¡ • IA32 ¡is: ¡ – LiNle ¡endian ¡ – NOT ¡load/store ¡ – CISC ¡ – Byte ¡(1 ¡byte), ¡word ¡(2 ¡bytes), ¡long ¡(4 ¡bytes) ¡ 6 ¡

  7. C ¡program ¡to ¡IA32 ¡and ¡Y86 ¡ • Computes ¡the ¡sum ¡of ¡an ¡integer ¡array ¡ int ¡Sum(int ¡*Start, ¡int ¡Count) ¡ ASSEMBLY ¡COMPARISON ¡ON ¡NEXT ¡SLIDE ¡ ¡ { ¡ Why ¡not ¡using ¡array ¡indexing ¡(i.e. ¡subscrip>ng)? ¡ ¡ ¡ ¡ ¡ ¡int ¡sum ¡= ¡0; ¡ No, ¡scaled ¡addressing ¡modes ¡in ¡Y86 ¡ ¡ ¡ ¡ ¡ ¡while ¡(Count) ¡ ¡ ¡ ¡ ¡ ¡ ¡{ ¡ Uses ¡stack ¡and ¡frame ¡pointers ¡ ¡sum ¡+= ¡*Start; ¡ ¡ ¡Start++; ¡ For ¡simplicity, ¡does ¡not ¡follow ¡IA32 ¡conven>on ¡ ¡Count-­‑-­‑; ¡ of ¡having ¡some ¡registers ¡designated ¡as ¡callee-­‑ ¡ ¡ ¡ ¡ ¡} ¡ save ¡registers ¡(conven>on ¡so ¡adopt ¡or ¡ignore ¡as ¡ } ¡ we ¡please) ¡ 7 ¡

  8. IA32/Y86 ¡comparison ¡ 8 ¡

  9. CHAPTER ¡3.2 ¡Program ¡Encodings ¡ GOAL ¡ è ¡examine ¡assembly ¡code ¡and ¡map ¡it ¡back ¡to ¡the ¡constructs ¡found ¡in ¡high-­‑ • level ¡programming ¡languages ¡ %gcc ¡–O1 ¡–m32 ¡–S ¡code.c ¡ à ¡code.s ¡ • %more ¡code.s ¡ • – Runs ¡the ¡compiler ¡only ¡ – -­‑S ¡op>ons ¡= ¡generates ¡an ¡assembly ¡(.s) ¡file ¡ – -­‑O1 ¡is ¡an ¡op>miza>on ¡level ¡ – All ¡informa>on ¡about ¡local ¡variables ¡names ¡or ¡data ¡types ¡have ¡been ¡stripped ¡away ¡ – S>ll ¡see ¡global ¡variable ¡“accum” ¡ • Compiler ¡has ¡not ¡yet ¡determined ¡where ¡in ¡memory ¡this ¡variable ¡will ¡be ¡stored ¡ %gcc ¡–O1 ¡–c ¡–m32 ¡code.c ¡ à ¡code.o ¡ • %objdump ¡–d ¡code.o ¡ • – -­‑c ¡compiles ¡and ¡assembles ¡the ¡code ¡ – Generates ¡an ¡object-­‑code ¡file ¡(.o) ¡= ¡binary ¡format ¡ – DISASSEMBLER ¡– ¡re-­‑engineers ¡the ¡object ¡code ¡back ¡into ¡assembly ¡language ¡ – %uname ¡–p ¡ – -­‑m32 ¡is ¡a ¡gcc ¡op>on ¡to ¡run/build ¡32-­‑bit ¡applica>ons ¡on ¡a ¡64-­‑bit ¡machine ¡ 9 ¡

  10. Machine ¡code ¡vs ¡C ¡code ¡ • Program ¡Counter ¡(PC) ¡ – Register ¡%eip ¡(X86-­‑64) ¡ – Address ¡in ¡memory ¡of ¡the ¡next ¡instruc>on ¡to ¡be ¡executed ¡ • Integer ¡Register ¡File ¡ – Contains ¡eight ¡named ¡loca>ons ¡for ¡storing ¡32-­‑bit ¡values ¡ • Can ¡hold ¡addresses ¡(C ¡pointers) ¡or ¡integer ¡data ¡ • Have ¡other ¡special ¡du>es ¡ • Condi>on ¡Code ¡registers ¡ – Hold ¡status ¡informa>on ¡ • About ¡arithme>c ¡or ¡logical ¡instruc>on ¡executed ¡ – CF ¡(carry ¡flag) ¡ – OF ¡(overflow ¡flag) ¡ – SF ¡(sign ¡flag) ¡ – ZF ¡(zero ¡flag) ¡ • Floa>ng ¡point ¡registers ¡ 10 ¡

  11. Machine ¡Instruc/on ¡Example ¡ • C ¡code ¡ int ¡ ¡t ¡= ¡x ¡+ ¡y; ¡ – Add ¡two ¡signed ¡integers ¡ ¡ • Assembly ¡ addl ¡8(%ebp),%eax ¡ – Add ¡2 ¡4-­‑byte ¡integers ¡ ¡ • Operands ¡ ¡ – X: ¡register ¡%eax ¡ ¡ – Y: ¡memory ¡M[%ebp+8] ¡ ¡ – T: ¡register ¡%eax ¡ ¡ – Return ¡func>on ¡value ¡in ¡%eax ¡ ¡ • Object ¡code ¡ 03 ¡45 ¡08 ¡ ¡ – 3 ¡byte ¡instruc>on ¡ – Stored ¡at ¡address: ¡0x???????? ¡ 11 ¡

  12. IA32 ¡– ¡Intel ¡Architecture ¡ 32-­‑bit ¡address ¡bus ¡ • – normal ¡physical ¡address ¡space ¡of ¡4 ¡GBytes ¡(2 32 ¡ bytes) ¡ – addresses ¡ranging ¡con>nuously ¡from ¡0 ¡to ¡0xFFFFFFFF ¡ Complex ¡instruc>on ¡set ¡(CISC) ¡machine ¡ • Data ¡formats ¡ à ¡ • C ¡Declara/on ¡ Suffix ¡ Name ¡ Size ¡ ¡ – Primi>ve ¡data ¡types ¡of ¡C ¡ char ¡ B ¡ BYTE ¡ 8 ¡bits ¡ ¡ – Single ¡byte ¡suffix ¡ ¡ short ¡ W ¡ WORD ¡ 16 ¡bits ¡ ¡ • denotes ¡size ¡of ¡operand ¡ int ¡ L ¡ LONG ¡ 32 ¡bits ¡ ¡ – No ¡aggregate ¡types ¡ • Arrays, ¡structures ¡ char ¡* ¡(pointer) ¡ L ¡ LONG ¡ 32 ¡bits ¡ Registers ¡(see ¡handout) ¡ • float ¡ S ¡ SINGLE ¡ 32 ¡bits ¡ – six ¡(almost) ¡general ¡purpose ¡32-­‑bit ¡registers: ¡ ¡ • %eax, ¡%ebx, ¡%ecx, ¡%edx, ¡%esi, ¡%edi ¡ – two ¡specialty ¡ à ¡stack ¡pointer ¡and ¡base/frame ¡pointer: ¡ • %esp, ¡%ebp ¡ – Float ¡values ¡are ¡in ¡different ¡registers ¡(later) ¡ • a ¡floa>ng-­‑point ¡processing ¡unit ¡(FPU) ¡with ¡eight ¡80-­‑bit ¡wide ¡registers: ¡st(0) ¡to ¡st(7) ¡ 12 ¡

  13. Outline ¡ • Introduc>on ¡of ¡IA32 ¡ • IA32 ¡opera>ons ¡ – Data ¡movement ¡opera>ons ¡ – Stack ¡opera>ons ¡and ¡func>on ¡calls ¡ – Arithme>c ¡and ¡logic ¡opera>ons ¡ – Compare ¡and ¡jump ¡opera>ons ¡ • Instruc>on ¡encoding ¡format ¡ • Array ¡and ¡structures ¡alloca>on ¡and ¡access ¡ 13 ¡

  14. Operand ¡Specifiers ¡ • Source ¡operand ¡ – Constants, ¡registers, ¡or ¡memory ¡ • Des>na>on ¡operand ¡ – Registers ¡or ¡memory ¡ • CANNOT ¡DO ¡MEMORY-­‑MEMORY ¡TRANSFER ¡ WITH ¡A ¡SINGLE ¡INSTRUCTION ¡ • 3 ¡types ¡of ¡operands ¡ – Immediate ¡– ¡for ¡constant ¡values ¡ – Register ¡ ¡ – Memory ¡ 14 ¡

  15. Operand ¡Combina/ons ¡example ¡ Source ¡ Dest ¡ Src,Dest* ¡ C ¡analog ¡ Immediate ¡ Register ¡ movl ¡$0x4, ¡%eax ¡ temp ¡= ¡0x4; ¡ Immediate ¡ Memory ¡ movl ¡$-­‑147, ¡(%eax) ¡ *p ¡= ¡-­‑147; ¡ Register ¡ Register ¡ movl ¡%eax, ¡%edx ¡ temp2 ¡= ¡temp1; ¡ Register ¡ Memory ¡ movl ¡%eax, ¡(%edx) ¡ *p ¡= ¡temp; ¡ Memory ¡ Register ¡ movl ¡(%eax), ¡%edx ¡ temp ¡= ¡*p; ¡ • Each ¡statement ¡should ¡be ¡viewed ¡separately. ¡ • REMINDER: ¡cannot ¡do ¡memory-­‑memory ¡transfer ¡with ¡a ¡single ¡instruc>on. ¡ • The ¡parentheses ¡around ¡the ¡register ¡tell ¡the ¡assembler ¡to ¡use ¡the ¡register ¡ as ¡a ¡pointer. ¡ 15 ¡

  16. Addressing ¡Modes ¡ Examples ¡on ¡next ¡slide ¡ • An ¡ addressing ¡mode ¡ is ¡a ¡mechanism ¡for ¡specifying ¡an ¡ address. ¡ – Immediate ¡ ¡ – Register ¡ – Memory ¡ • Absolute ¡ – specify ¡the ¡address ¡of ¡the ¡data ¡ • Indirect ¡ – use ¡register ¡to ¡calculate ¡address ¡ • Base ¡+ ¡displacement ¡ – use ¡register ¡plus ¡absolute ¡address ¡to ¡calculate ¡address ¡ • Indexed ¡ – Indexed ¡ » Add ¡contents ¡of ¡an ¡index ¡register ¡ – Scaled ¡index ¡ » Add ¡contents ¡of ¡an ¡index ¡register ¡scaled ¡by ¡a ¡constant ¡ 16 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend