marie simulator
play

MARIE Simulator 2 Discussion What was easy about - PowerPoint PPT Presentation

Computer Systems and Networks ECPE 170 Jeff Shafer University of the Pacific MARIE Simulator 2 Discussion What was easy about


  1. ì ¡ Computer ¡Systems ¡and ¡Networks ¡ ECPE ¡170 ¡– ¡Jeff ¡Shafer ¡– ¡University ¡of ¡the ¡Pacific ¡ MARIE ¡Simulator ¡

  2. 2 ¡ Discussion ¡ ì What ¡was ¡easy ¡about ¡programming ¡MARIE? ¡ ì What ¡was ¡hard ¡about ¡programming ¡MARIE? ¡ ì What ¡:ps ¡would ¡you ¡share ¡to ¡other ¡beginning ¡ assembly ¡programmers? ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  3. 3 ¡ MARIE ¡Programming ¡Tip ¡ ì WriCng ¡code ¡in ¡assembly ¡ ¡can ¡be ¡inCmidaCng ¡at ¡ first ¡ ì High-­‑level ¡languages ¡are ¡(much!) ¡easier ¡to ¡use ¡ ì Treat ¡the ¡problem ¡like ¡a ¡complier ¡would ¡ ì Think ¡about ¡how ¡to ¡code ¡in ¡another ¡language, ¡ ¡ like ¡C++ ¡ ì Convert ¡each ¡construct ¡into ¡a ¡series ¡of ¡MARIE ¡ instrucCons ¡ ì Variables ¡first, ¡then ¡funcCons, ¡loops, ¡if ¡statements, ¡… ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  4. 4 ¡ SKIPCOND ¡Operation ¡ ì SKIPCOND 000 ì if(AC ¡< ¡0) ¡skip ¡next ¡instrucCon ¡ ì SKIPCOND 400 ì if(AC ¡== ¡0) ¡skip ¡next ¡instrucCon ¡ ì SKIPCOND 800 ì if(AC ¡> ¡0) ¡skip ¡next ¡instrucCon ¡ ì SKIPCOND 800 ¡= ¡ 1000 1000 0000 0000 Upper ¡2 ¡bits ¡of ¡“address” ¡field ¡ determine ¡which ¡comparison ¡ SKIPCOND ¡will ¡use! ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  5. 5 ¡ Assembly ¡Pitfall ¡– ¡Program ¡Organization ¡ ì The ¡assembler ¡and ¡CPU ¡do ¡exactly ¡what ¡we ¡tell ¡it. ¡ ì However, ¡that ¡doesn’t ¡always ¡mean ¡it ¡does ¡what ¡we ¡ intend! ¡ ì You ¡must ¡be ¡very ¡explicit ¡when ¡organizing ¡your ¡ program ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  6. 6 ¡ Assembly ¡Pitfall ¡– ¡Program ¡Organization ¡ ì What ¡did ¡the ¡programmer ¡ intend ¡for ¡this ¡code ¡to ¡do? ¡ LOAD X Z=X+Y ¡ ì ADD Y X, DEC 6 ì What ¡does ¡the ¡program ¡ actually ¡do? ¡ Y, DEC -3 Our ¡variable ¡X ¡( 0006 ) ¡gets ¡ ì Z, DEC 0 interpreted ¡as ¡a ¡ ¡ STORE Z JNS ¡6 ¡instrucCon! ¡ HALT Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  7. 7 ¡ Assembly ¡Pitfall ¡– ¡Program ¡Organization ¡ ì Code ¡should ¡always ¡jump ¡ around ¡any ¡data ¡ LOAD X ADD Y ì Compilers ¡did ¡this ¡for ¡you ¡in ¡ JMP SKIP COMP ¡51 ¡ X, DEC 6 AutomaCcally ¡separate ¡ ì code ¡and ¡data ¡ Y, DEC -3 Z DEC 0 SKIP, STORE Z HALT Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  8. 8 ¡ Homework ¡#9 ¡Discussion ¡ ì Discuss ¡algorithms ¡for ¡Problems ¡28 ¡and ¡29… ¡ ¡ ì How ¡many ¡people ¡submiQed ¡working ¡.mas ¡files ¡ that ¡I ¡can ¡open ¡in ¡the ¡simulator ¡and ¡run? ¡ ì Would ¡you ¡like ¡an ¡opportunity ¡to ¡re-­‑submit ¡a ¡ working ¡program? ¡(deadline: ¡midnight?) ¡ ì Discuss ¡schedule ¡ ì Homework ¡10? ¡ ì Quiz ¡3? ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  9. 9 ¡ Upcoming ¡Schedule ¡ ì Monday ¡20 th ¡– ¡No ¡class ¡ ¡ ì Wednesday ¡22 nd ¡ ì MARIE ¡assembly ¡programming ¡ ì Homework ¡#10 ¡Due ¡ ì Friday ¡24 th ¡ ¡ ì Start ¡Chapter ¡5 ¡ ì Quiz ¡3! ¡ ì Topic: ¡Assembly ¡programming! ¡ ì I ¡will ¡give ¡you ¡Table ¡4.7 ¡from ¡the ¡book ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  10. 10 ¡ ì ¡ Subroutines ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  11. 11 ¡ Subroutines ¡ ì Result = addOne(input1); ì What ¡do ¡we ¡need ¡for ¡a ¡subrou:ne? ¡(i.e. ¡func:on) ¡ ì Arguments ¡to ¡the ¡funcCon ¡(i.e. ¡input ¡data) ¡ ì Return ¡value ¡from ¡the ¡funcCon ¡ ì A ¡way ¡to ¡jump ¡to ¡the ¡funcCon ¡ ì A ¡way ¡to ¡return ¡from ¡the ¡funcCon ¡when ¡finished ¡ ì Let’s ¡write ¡a ¡subrou:ne ¡that ¡increments ¡a ¡number ¡ by ¡1 ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  12. 12 ¡ Subroutine ¡Example ¡(Add ¡One ¡to ¡Num) ¡ Load Data / get value Store Arg1 / store value as argument Jns AddOne / call subroutine Load Return / load subroutine return data Output / print it! Halt / terminate Data, Dec 20 / original value / ** Subroutine ** AddOne, Dec 0 / return address placed here Load Arg1 / get argument Add One / increment it Store Return / save return value JumpI AddOne / return with value in a Arg1, Dec 0 / Empty: subroutine argument Return, Dec 0 / Empty: subroutine return value Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  13. 13 ¡ ì ¡ Clever ¡Tricks ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  14. 14 ¡ Clever ¡Tricks ¡– ¡Memory ¡Addresses ¡ ORG 100 / Example 4.1 Load Addr /Load address of first number to be added Store Next /Store this address is our Next pointer ì Think ¡back ¡to ¡first ¡ Load Num /Load the number of items to be added Subt One /Decrement MARIE ¡program ¡ Store Ctr /Store this value in Ctr to control looping Loop, Load Sum /Load the Sum into AC (Example ¡4.1) ¡ AddI Next /Add the value pointed to by location Next Store Sum /Store this sum Load Next /Load Next Add One /Increment by one to point to next address ì ADDR ¡variable ¡ Store Next /Store in our pointer Next Load Ctr /Load the loop control variable holds ¡the ¡address ¡ Subt One /Subtract one from the loop control variable Store Ctr /Store this new value in loop control variable of ¡the ¡element ¡to ¡ Skipcond 000 /If control variable < 0, skip next instruction Jump Loop /Otherwise, go to Loop be ¡added ¡ Halt /Terminate program Addr, Hex 117 /Numbers to be summed start at location 117 Next, Hex 0 /A pointer to the next number to add ì It’s ¡a ¡pointer ¡ Num, Dec 5 /The number of values to add Sum, Dec 0 /The sum ì Value ¡= ¡0x117 ¡ Ctr, Hex 0 /The loop control variable One, Dec 1 /Used to increment and decrement by 1 Dec 10 /The values to be added together Dec 15 Dec 20 This ¡is ¡loca*on ¡117 ¡ Dec 25 Dec 30 Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  15. 15 ¡ Clever ¡Tricks ¡– ¡Memory ¡Addresses ¡ ì What ¡happens ¡if ¡the ¡program ¡changes? ¡ ì Say, ¡we ¡add ¡a ¡few ¡instrucCons ¡ ¡ ì We ¡would ¡have ¡to ¡find ¡the ¡ new ¡starCng ¡address ¡of ¡ the ¡data, ¡save ¡its ¡value ¡in ¡our ¡assembly ¡code, ¡and ¡ re-­‑run ¡the ¡assembler ¡ ì Annoying! ¡ ADDR, HEX 125 Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  16. 16 ¡ Clever ¡Tricks ¡– ¡Memory ¡Addresses ¡ ì Perfect ¡world: ¡The ¡assembler ¡lets ¡us ¡use ¡a ¡label ¡and ¡ fills ¡in ¡the ¡address ¡from ¡the ¡symbol ¡table ¡on ¡pass ¡2 ¡ ì Unfortunately ¡we ¡don’t ¡live ¡in ¡this ¡perfect ¡world! ¡ ì Assembler ¡doesn’t ¡do ¡this ¡directly, ¡but ¡we ¡can ¡fool ¡it ¡ into ¡doing ¡something ¡similarly ¡useful ¡ ì SoluCon ¡takes ¡advantage ¡of ¡the ¡fact ¡that ¡the ¡ instrucCon ¡format ¡always ¡uses ¡the ¡lower ¡12 ¡bits ¡of ¡ each ¡instrucCon ¡for ¡the ¡address ¡ ì i.e. ¡this ¡soluCon ¡works ¡for ¡MARIE, ¡but ¡not ¡ necessarily ¡other ¡assembly ¡languages ¡ Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

  17. 17 ¡ Clever ¡Tricks ¡– ¡Memory ¡Addresses ¡ ì What ¡happens ¡when ¡these ¡ 100 Load Addr changes ¡are ¡made ¡to ¡the ¡ 101 Store Next example ¡program? ¡ … 106 Addi Next … 111 Addr, JnS List 112 Next, Hex 0 … 116 One, Dec 1 117 List, Dec 10 Computer ¡Systems ¡and ¡Networks ¡ Spring ¡2012 ¡

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