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 ¡opera5ons ¡ • 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 ¡– ¡Instruc5on ¡Set ¡Architecture ¡ 5 ¡

  6. ISA-­‑More ¡explana5ons ¡ 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) ¡ • 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 ¡Instruc5on ¡Cycle ¡ An ¡ instruc5on ¡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. Hardware ¡abstrac5ons ¡ • 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 ¡ • Floa5ng ¡point ¡registers ¡ • Condi5on ¡Code ¡registers ¡ – Hold ¡status ¡informa5on ¡ • About ¡arithme5c ¡or ¡logical ¡instruc5on ¡executed ¡ – CF ¡(carry ¡flag) ¡ – OF ¡(overflow ¡flag) ¡ – SF ¡(sign ¡flag) ¡ – ZF ¡(zero ¡flag) ¡ • Memory ¡ 8 ¡

  9. Machine ¡instruc5on ¡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???????? ¡ 9 ¡

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

  11. Y86: ¡A ¡simpler ¡instruc5on ¡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 ¡ 11 ¡

  12. Y86 ¡abstrac5ons ¡ • 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 ¡ ¡ hsp://voices.yahoo.com/the-­‑y86-­‑processor-­‑simulator-­‑770435.html?cat=15 ¡ hsp://y86tutoring.wordpress.com/ ¡ 12 ¡

  13. Y86 ¡Memory ¡and ¡Stack ¡ ¡ high ¡address ¡ 1. A ¡huge ¡array ¡of ¡bytes; ¡ Y86 ¡Stack ¡ 2. Set ¡the ¡bosom ¡of ¡the ¡stack ¡ far ¡enough ¡away ¡from ¡the ¡ code; ¡ 3. The ¡loca5on ¡of ¡your ¡code ¡ should ¡always ¡start ¡from ¡ 0x0. ¡ ¡ How ¡to ¡set ¡up ¡the ¡star5ng ¡point ¡ of ¡stack ¡and ¡code? ¡ direc5ve: ¡.pos ¡address-­‑in-­‑hex ¡ Y86 ¡Code ¡ low ¡address ¡ 13 ¡

  14. YIS ¡and ¡YAS ¡and ¡the ¡Y86 ¡simulator ¡ • Check: ¡1) ¡How ¡to ¡set ¡up ¡$PATH; ¡2) ¡How ¡to ¡connect ¡Linux ¡with ¡X ¡display ¡ ¡ ¡ • Add ¡these ¡variables ¡to ¡your ¡$PATH: ¡ – /home/f85/bren/Sovware/sim/misc ¡ – /home/f85/bren/Sovware/sim/pipe ¡ – /home/f85/bren/Sovware/sim/seq ¡ – The ¡example ¡code ¡was ¡assembled ¡during ¡the ¡build ¡process ¡and ¡is ¡in ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡/home/f85/bren/Sovware/sim/y86-­‑code. ¡ ¡ • HOW ¡TO: ¡ – %yas ¡prog.ys ¡ • Assembles ¡the ¡program ¡ • Creates ¡a ¡*.yo ¡file ¡ – %yis ¡prog.yo ¡ • Instruc5on ¡set ¡simulator ¡– ¡gives ¡output ¡and ¡changes ¡ – %ssim ¡–g ¡ ¡prog.yo ¡& ¡ • SimGuide ¡ – link à ¡ ¡hsp://csapp.cs.cmu.edu/public/simguide.pdf ¡ 14 ¡

  15. Run ¡Y86 ¡program ¡ % ¡yas ¡y86prog1.ys ¡ irmovl ¡$55,%edx ¡ % ¡yis ¡y86prog1.yo ¡ rrmovl ¡%edx, ¡%ebx ¡ Stopped ¡in ¡6 ¡steps ¡at ¡PC ¡= ¡0x1a. ¡ irmovl ¡Array, ¡%eax ¡ Status ¡'HLT' ¡ rmmovl ¡%ebx,4(%eax) ¡ CC ¡Z=1 ¡S=0 ¡O=0 ¡ mrmovl ¡0(%eax),%ecx ¡ Changes ¡to ¡registers: ¡ halt ¡ %eax: ¡0x00000000 ¡0x0000001c ¡ %ecx: ¡0x00000000 ¡0x0000006f ¡ .align ¡4 ¡ %edx: ¡0x00000000 ¡0x00000037 ¡ Array: ¡ %ebx: ¡0x00000000 ¡0x00000037 ¡ .long ¡0x6f ¡ ¡ .long ¡0x84 ¡ Changes ¡to ¡memory: ¡ 0x0020: ¡0x00000084 ¡0x00000037 ¡ y86prog1.ys ¡ 15 ¡

  16. Y86 ¡Simulator ¡program ¡code ¡ 16 ¡

  17. Y86 ¡Simulator ¡ • Contents ¡of ¡ memory ¡ • Processor ¡State ¡ – The ¡fetch-­‑ execute ¡loop ¡ • Register ¡file ¡ • Status ¡ • Condi5on ¡Codes ¡ 17 ¡

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