reading assignment
play

Reading Assignment Chapter 3.1, 3.2 Chapter 4.1, 4.3 1 - PowerPoint PPT Presentation

Reading Assignment Chapter 3.1, 3.2 Chapter 4.1, 4.3 1 Outline Introduc5on to assembly programing Introduc5on to Y86 Y86 instruc5ons, encoding


  1. Reading ¡Assignment ¡ • Chapter ¡3.1, ¡3.2 ¡ • Chapter ¡4.1, ¡4.3 ¡ 1 ¡

  2. Outline ¡ • Introduc5on ¡to ¡assembly ¡programing ¡ • Introduc5on ¡to ¡Y86 ¡ • Y86 ¡instruc5ons, ¡encoding ¡and ¡execu5on ¡ 2 ¡

  3. Assembly ¡ • The ¡CPU ¡uses ¡machine ¡language ¡to ¡perform ¡all ¡its ¡ opera5ons ¡ ¡ • Machine ¡code ¡(pure ¡numbers) ¡is ¡generated ¡by ¡transla5ng ¡ each ¡instruc5on ¡into ¡binary ¡numbers ¡that ¡the ¡CPU ¡uses ¡ ¡ • This ¡process ¡is ¡called ¡"assembling"; ¡conversely, ¡we ¡can ¡take ¡ assembled ¡code ¡and ¡disassemble ¡it ¡into ¡(mostly) ¡human ¡ readable ¡assembly ¡language ¡ ¡ • Assembly ¡is ¡a ¡much ¡more ¡readable ¡transla5on ¡of ¡machine ¡ language, ¡and ¡it ¡is ¡what ¡we ¡work ¡with ¡if ¡we ¡need ¡to ¡see ¡ what ¡the ¡computer ¡is ¡doing ¡ ¡ • There ¡are ¡many ¡different ¡kinds ¡of ¡assembly ¡languages; ¡we'll ¡ focus ¡on ¡the ¡Y86/IA32 ¡language ¡as ¡defined ¡in ¡the ¡text ¡and ¡ on ¡our ¡system ¡(also ¡SPARC ¡and ¡MIPS) ¡ 3 ¡

  4. Assembly ¡Opera4ons ¡ • Perform ¡arithme5c ¡func5on ¡on ¡register ¡or ¡ memory ¡data ¡ • Transfer ¡data ¡between ¡memory ¡and ¡register ¡ – Load ¡data ¡from ¡memory ¡into ¡register ¡(read) ¡ – Store ¡register ¡data ¡into ¡memory ¡(write) ¡ • Transfer ¡control ¡ – Uncondi5onal ¡jumps ¡to/from ¡procedures ¡(calls) ¡ – Condi5onal ¡branches ¡(if, ¡switch, ¡for, ¡while, ¡etc) ¡ 4 ¡

  5. ISA ¡– ¡Instruc4on ¡Set ¡Architecture ¡ 5 ¡

  6. Machine-­‑level ¡code ¡ ¡ • ISA ¡– ¡instruc5on ¡set ¡architecture ¡ – Format ¡and ¡behavior ¡of ¡a ¡machine ¡level ¡program ¡ – Defines: ¡ • The ¡processor ¡state ¡(see ¡the ¡CPU ¡fetch-­‑execute ¡cycle) ¡ • The ¡format ¡of ¡the ¡instruc5ons ¡ • The ¡effect ¡of ¡each ¡of ¡these ¡instruc5ons ¡on ¡the ¡state ¡ – Abstrac5ons ¡ • Instruc5on ¡executed ¡“in ¡sequence” ¡ – Technically ¡defined ¡to ¡be ¡comple5ng ¡one ¡instruc5on ¡before ¡star5ng ¡the ¡next ¡ – Pipelining ¡ – Concurrent ¡execu5on ¡(but ¡not ¡really) ¡ – Jumps ¡and ¡calls ¡ • Memory ¡addresses ¡are ¡virtual ¡addresses ¡ – Very ¡large ¡byte-­‑addressable ¡array ¡ – Address ¡space ¡managed ¡by ¡the ¡OS ¡(virtual ¡ à ¡physical) ¡ – Contains ¡both ¡executable ¡code ¡of ¡the ¡program ¡AND ¡its ¡data ¡ » Run-­‑5me ¡stack ¡ » Block ¡of ¡memory ¡for ¡user ¡(global ¡and ¡heap) ¡ 6 ¡

  7. Generic ¡CPU ¡ Fetch-­‑Execute ¡ cycle ¡ An ¡ instruc4on ¡cycle ¡is ¡the ¡basic ¡opera5on ¡cycle ¡ of ¡a ¡computer. ¡It ¡is ¡the ¡process ¡by ¡which ¡a ¡ computer ¡retrieves ¡a ¡program ¡instruc5on ¡from ¡its ¡ memory, ¡determines ¡what ¡ac5ons ¡the ¡instruc5on ¡ requires, ¡and ¡carries ¡out ¡those ¡ac5ons. ¡This ¡cycle ¡ is ¡repeated ¡con5nuously ¡by ¡the ¡central ¡ processing ¡unit ¡(CPU), ¡from ¡bootup ¡to ¡when ¡the ¡ computer ¡is ¡shut ¡down. ¡ ¡ 1. ¡Fetching ¡the ¡instruc5on ¡ 2. ¡Decode ¡the ¡instruc5on ¡ 3. ¡Memory ¡and ¡addressing ¡issues ¡ 4. ¡Execute ¡the ¡instruc5on ¡ 7 ¡

  8. CPU ¡Fetch-­‑Execute ¡cycle ¡ Ini4a4ng ¡the ¡cycle ¡ • The ¡cycle ¡starts ¡immediately ¡when ¡power ¡is ¡applied ¡to ¡the ¡system ¡using ¡an ¡ini5al ¡PC ¡value ¡that ¡is ¡ – predefined ¡for ¡the ¡system ¡architecture ¡( in ¡Intel ¡IA-­‑32 ¡CPUs, ¡for ¡instance, ¡the ¡predefined ¡PC ¡value ¡is ¡ 0xfffffff0 ). ¡Typically ¡this ¡address ¡points ¡to ¡instruc5ons ¡in ¡a ¡read-­‑only ¡memory ¡(ROM) ¡which ¡begin ¡the ¡ process ¡of ¡loading ¡the ¡opera5ng ¡system. ¡(That ¡loading ¡process ¡is ¡called ¡ boo#ng. ) ¡ • Fetch ¡cycle ¡ Step ¡1 ¡of ¡the ¡Instruc5on ¡Cycle ¡is ¡called ¡the ¡Fetch ¡Cycle. ¡These ¡steps ¡are ¡the ¡same ¡for ¡each ¡ – instruc5on. ¡The ¡fetch ¡cycle ¡processes ¡the ¡instruc5on ¡from ¡the ¡instruc5on ¡word ¡which ¡contains ¡an ¡ opcode. ¡ • Decode ¡ Step ¡2 ¡of ¡the ¡instruc5on ¡Cycle ¡is ¡called ¡the ¡decode. ¡The ¡opcode ¡fetched ¡from ¡the ¡memory ¡is ¡being ¡ – decoded ¡for ¡the ¡next ¡steps ¡and ¡moved ¡to ¡the ¡appropriate ¡registers. ¡ • Read ¡the ¡effec4ve ¡address ¡ Step ¡3 ¡is ¡deciding ¡which ¡opera5on ¡it ¡is. ¡If ¡this ¡is ¡a ¡Memory ¡opera5on ¡-­‑ ¡in ¡this ¡step ¡the ¡computer ¡ – checks ¡if ¡it's ¡a ¡direct ¡or ¡indirect ¡memory ¡opera5on: ¡ • Direct ¡memory ¡instruc4on ¡-­‑ ¡Nothing ¡is ¡being ¡done. ¡ • Indirect ¡memory ¡instruc4on ¡-­‑ ¡The ¡effec5ve ¡address ¡is ¡being ¡read ¡from ¡the ¡memory. ¡ If ¡this ¡is ¡a ¡I/O ¡or ¡Register ¡instruc5on ¡-­‑ ¡the ¡computer ¡checks ¡its ¡kind ¡and ¡execute ¡the ¡instruc5on. ¡ – • Execute ¡cycle ¡ Step ¡4 ¡of ¡the ¡Instruc5on ¡Cycle ¡is ¡the ¡Execute ¡Cycle. ¡These ¡steps ¡will ¡change ¡with ¡each ¡instruc5on. ¡ – 8 ¡

  9. Machine ¡code ¡vs ¡C ¡code ¡ • Program ¡Counter ¡(PC) ¡ – Register ¡%eip ¡(X86-­‑64) ¡ – Address ¡in ¡memory ¡of ¡the ¡next ¡instruc5on ¡to ¡be ¡executed ¡ • Integer ¡Register ¡File ¡ – Contains ¡eight ¡named ¡loca5ons ¡for ¡storing ¡32-­‑bit ¡values ¡ • Can ¡hold ¡addresses ¡(C ¡pointers) ¡or ¡integer ¡data ¡ • Have ¡other ¡special ¡du5es ¡ • Condi5on ¡Code ¡registers ¡ – Hold ¡status ¡informa5on ¡ • About ¡arithme5c ¡or ¡logical ¡instruc5on ¡executed ¡ – CF ¡(carry ¡flag) ¡ – OF ¡(overflow ¡flag) ¡ – SF ¡(sign ¡flag) ¡ – ZF ¡(zero ¡flag) ¡ • Floa5ng ¡point ¡registers ¡ 9 ¡

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

  11. Outline ¡ • Introduc5on ¡to ¡assembly ¡programing ¡ • Introduc5on ¡to ¡Y86 ¡ • Y86 ¡instruc5ons, ¡encoding ¡and ¡execu5on ¡ 11 ¡

  12. Y86: ¡A ¡simpler ¡instruc4on ¡set ¡ • IA32 ¡has ¡a ¡lot ¡more ¡instruc5ons ¡ • IA32 ¡has ¡a ¡lot ¡of ¡quirks ¡ • Y86 ¡is ¡a ¡subset ¡of ¡IA32 ¡instruc5ons ¡ • Y86 ¡has ¡a ¡simpler ¡encoding ¡scheme ¡than ¡IA32 ¡ • Y86 ¡is ¡easier ¡to ¡reason ¡about ¡ • hardware ¡ ¡ • first ¡5me ¡programming ¡in ¡assembly ¡language ¡ 12 ¡

  13. About ¡Y86 ¡ • The ¡Y86 ¡has ¡ ¡ – 8 ¡32-­‑bit ¡registers ¡with ¡the ¡same ¡names ¡as ¡the ¡IA32 ¡32-­‑bit ¡ registers ¡ ¡ – 3 ¡condi5on ¡codes: ¡ZF, ¡SF, ¡OF ¡ ¡ • no ¡carry ¡flag ¡ ¡ • interprets ¡integers ¡as ¡signed ¡ – a ¡program ¡counter ¡(PC) ¡ ¡ – a ¡program ¡status ¡byte: ¡AOK, ¡HLT, ¡ADR, ¡INS ¡ ¡ – memory: ¡up ¡to ¡4 ¡GB ¡to ¡hold ¡program ¡and ¡data ¡ ¡ • The ¡Y86 ¡does ¡not ¡have: ¡ ¡ – floa5ng ¡point ¡registers ¡or ¡instruc5ons ¡ ¡ htp://voices.yahoo.com/the-­‑y86-­‑processor-­‑simulator-­‑770435.html?cat=15 ¡ htp://y86tutoring.wordpress.com/ ¡ 13 ¡

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