lab1 visual emulator - sonoma state university€¦ · lab1_visual_emulator author: farid farahmand...

13
LAB 1 Using Visual Emulator Download the emulator https://salmanarif.bitbucket.io/visual/downloads.html Answer to questions (Q)

Upload: others

Post on 26-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

LAB1UsingVisualEmulator

Downloadtheemulatorhttps://salmanarif.bitbucket.io/visual/downloads.html

Answertoquestions(Q)

Page 2: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

LoadthefollowingPrograminVisualEmulator;Thepurposeofthisprogramistoadd:aa+bb=cc

;Firstwedefinethevariables;Thevariablesarestoredinlocations0x100-0x108intheMEMMORY

aaDCD0x00112233 ;load(32bit)value0x00000001intomemorylocation0x100(bydefault)callitaa

bbDCD2;load(32bit)value0x00000002intomemorylocation0x104(bydefault)

ccDCD0;load(32bit)value0x00000000intomemorylocation0x108(bydefault)

mainLDRr1, =aa;loadmemoryaddressofaaintor1Afterexecution:PC=0xC+4LDRr2,[r1];loadcontentofmemoryaddressinr1intor2(thatis0x0001)LDRr3,=bbLDRr4,[r3]ADDSr5,r2,r4;r2+r4->r5andupdateflagsLDRr6,=cc;loadmemoryaddressofccintor6STRr5,[r6];storethesumintovariablecc;thissectionshowsthatthesumisinfact loadedintoccLDRr7,=ccLDRr8,[r7];cc+1-->r9ADDSr9,r8,#1END

DCB Define Constant Byte Reserve 8-bit values

DCW Define Constant Half-word

Reserve 16-bit values

DCD Define Constant Word Reserve 32-bit values

DCQ Define Constant Reserve 64-bit values

Page 3: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

ExecutetheProgram:ClickonStepFroward

Page 4: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Seewhathappensasyoustepthrough

NotehowregistersR1-R9changeNotethatthememoryaddressforaais0x100,forbbis0x104andsofar….ClickonHEXBINandDECandseethevalues.Question:Q1.WhatisthelargestvalueofaavariableinHEXandDECIMAL?Howmanybitsarerequiredtorepresentthisvalue?Q2.Whatisthememoryaddressofcc?

Page 5: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Seewhathappensasyoustepthrough

Notethateverytimeaninstructionisexecuted,thePCvalueisincreased.

NotethatasADDSisexecuted,thecolorofCSPRchangesindicatingitisbeingupdated.

Question:

Q3.Bythetimetheprogramiscompleted,whatisthevalueofPC?

Page 6: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Seewhathappensasyoustepthrough

NotethateverytimeaninstructionisexecutedtheINTRUCTIONclockcycleisincreased.

Question:Q4.HowmanyinstructioncyclesarerequiredtoexecuteADDSinstruction?Q5.HowmanyinstructioncyclesarerequiredtoexecuteSTRinstruction?Q6.Howmanyinstructioncyclesarerequiretocompletethiscode?

Page 7: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Asyouexecute….ClickonMEMORYwhenLDRisexecuted.NotethatyoucanseetheMemoryaddressforvariableaathisiswhereitissaved.Q7.Howmanybytesvariableaahas?

NotethateverytimeaninstructionisexecutedtheINTRUCTIONclockcycleisincreased.

Question:Q4.HowmanyinstructioncyclesarerequiredtoexecuteADDSinstruction?Q5.HowmanyinstructioncyclesarerequiredtoexecuteSTRinstruction?Q6.Howmanyinstructioncyclesarerequiretocompletethiscode?

Page 8: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

DATAMEMORYLOCATIONS

0x100 aa

0x104 bb

0x108 cc

INSTRUCTIONMEMORY LOCATIONS

Line1 0x00

Line 9 0x08

Line10 0x0C

TherearetwoseparatememorystructuresforDATAandINSTRUCTIONS.TheDATAMEMORYinthisEMUALTORstartsfrom0x100.However,theInstructionMEMORYstartsfrom0x0.WeknowthatbasedonthevalueofthePC

NotethatinthiscaseasPCincreases,itpointstoanewinstruction.Q8.WhatisthePCvalueAFTERADDS r9,r8,#1isexecutedQ9.WhatDoesPCstandfor?

Page 9: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

ADDthefollowingcodetotheendofyourprogram.StepthroughtheprogramandseehowR1changes.Q10.ClearlyexplainwhatishappeningtoR1.WhatdoesRRXinstructiondo?Q11.MathematicallyeverytimeRRXisperformedwhathappens?Q12.WhatdoesBinstructiondo?

NotethateverytimeaninstructionisexecutedtheINTRUCTIONclockcycleisincreased.

Question:Q4.HowmanyinstructioncyclesarerequiredtoexecuteADDSinstruction?Q5.HowmanyinstructioncyclesarerequiredtoexecuteSTRinstruction?Q6.Howmanyinstructioncyclesarerequiretocompletethiscode?

Page 10: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Trythefollowingcommands.Ineachcasespecifythepurposeofthecommand,whathappenstothedestinationregister

Examples Purpose? Whathappenstothedest.?

MOVr0,#42

MOVr2,r3

MVNr1,r0

MOVr0,r0

ADDr0,r1,r2

SUBr5,r3,#10

RSBr2,r5,#0xFF00

ANDr8,r7,r2

ORRr11,r11,#1

BICr11,r11,#1

EORr11,r11,#1ADC r5, r3 r1

MUL r6, r4, r2

Examples Purpose?

Whathappenstothedest.?

CMPr0,#42

CMNr2,#42

TSTr11,#1

MOVR2,R0,LSL#2

ADDR9,R5,R5,LSL#3

RSBR9,R5,R5,LSL#3

SUBR10,R9,R8,LSR#4

MOVR12,R4,RORR3

stopBstopSUBS r4, r0, r2

SBC r5, r1, r3

UMUL r6, r4, r2

MLS r6, r4, r1, r0

ADD r1, r0, r0, LSL #3

http://web.sonoma.edu/users/f/farahman/sonoma/courses/es310/310_arm/resources/datasheets/list_of_assembly_commands.pdf

Page 11: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Q.13PracticeWiththeFollowingCommandsADDSR1,R2,R3

MOVR1,R3

ADCR1,R2,#0;R9-R9+0+C

MOVR2,#0x4F

MOVR3,#0x39

SUBSR4,R2,R3;R4=R2-R3

MOVR2,#0x4F

SUBSR4,R2,#0x05;R4=R2-5

SUBR2,R2,R1:R2=R2-R1=4-64=0X4+FFFFFFC0=FFFFFFC4(2’SCOMP)

SUBR2,R2,#0x2;Immediatenumberoperand->R2=0x2

SUBR0,#1,R3;Notethisisanerror!

SBCR2,R2,R1;AssumeCarryis1????

MOVR1,#64 ;R1=0X01000000;alf-word

MOVR2,#0X4;R2=0X10001000

MULR3,R2,R1

TRYONECOMMANDATATIME:

MOVR1,#64 ;R1=0b01000000

MOVR2,#0X4;R2=0X10001000

MOVR3,#2;R3=0X00000010

MOVR4,#7;R4=0X00000111

MOVR5,#0XFF;R4=0XFF- MAXVALUETHATCANBELOADEDIS0XFF

ADDR1,R2,R3

aaDCD0xFFFFFFF5

LDRR0, =aa

LDRR1, [R0]

MOVR3,#0x0B

MOVR1,#10

MOVR2,#5

MOVR3,#2

MLAR4,R1,R2,R3;R4=R1xR2+R3orR3+=R1XR2

ANDSR4,R2,R3;R4=0X0ZFLAG

ANDSR4,R2,R3;R4=0X0NOGLAG

ORRSR4,R2,R3;R4=0X8A

ORRR5,R2,R3;Setabit!

EORR2,R1,#0x78;R2=R1ExOredwith0x78

BICR3,R2,#0x0F;R3=R2 AND0x0F

BICR3,R2,#~0x0F;R3=R2 ANDComplementof0x0F

LSLR1,R1,#1;R1=0X80

LSLR1,R2,#1;R1=0X110

LSLR1,R2,R3;R1=0X220 - NOFLAGUPDATE

LSLSR5,R5,#1;R5=0X1FE- NOTETHATN,Z,CFLAGSAREUPDATEDONLY(NOTV)

ADD R0, R2,R1, LSL #1 ; R0 = R2 + (R1 << 1) = 0X84

ROR R1, R1, #4 ;R1 = 0X4 —ROTATE TO RIGHT BY 4 BITSRRX R1, R4 ; ROTATE R4 BY ONE BIT AND PLACE IN R1=0X3

ADD R0, R2,R1, LSL #1 ; R0 = R2 + (R1 << 1) = 0X84

MOV R1, #0x36MOVS R1, R1, ROR #1 ;Rotate to right by one bitMOVS R1, R1, ROR #1 ;Rotate to right by one bit - C=1

MOV R1, #0x36MOV R2, #0x06MOVS R3, R2, ROR R1 ;Rotate to right by value of R1—> R3

http://web.sonoma.edu/users/f/farahman/sonoma/courses/es310/310_arm/resources/datasheets/list_of_assembly_commands.pdf

Page 12: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

UsethefollowingTabletoCompleteEachCommand– MustbesubmittedExamples Purpose? Whathappenstothedest.?

MOVr0,#42 Movingavalueintoaregister RegisterR0=42decimal/

Page 13: Lab1 Visual Emulator - Sonoma State University€¦ · Lab1_Visual_Emulator Author: Farid Farahmand Created Date: 2/8/2018 6:34:57 PM

Submitthefollowing:• Answerallthequestions.• Writeaprogramtodothefollowing:

• LoadR5with0x5• LoadR1with0x2• R2=R1+R2• R2=R1+R2• SetR5=0x20• StoreR2intolocationpointedbyR5

• Let’ssayweadd0x9Cand0xFFFFFF64.Whichflagswillbeset?Takeasnapshotofthesimulator.Explainyouranswer.• Let’ssayweadd0x9Cand0xFFFFFF69.Whichflagswillbeset?Takeasnapshotofthesimulator.Explainyouranswer.

• Writeaprogramtodothefollowing:• LoadR2with0x4• LoadR3with0x2• LoadR4with0x4• R5=R2-R3• R5=R2-R4• Whatistheisthestateoftheflags?

• Definea32-bitregistercalledSteveandsetitto0x2321.ThenmovetheaddressofStevetoregisterR2• Writeaninstructiontosetbit4ofR7only• WriteasimpleroutinethatcanaddTWO64-bitvalues.TheresultsmustbeinRegR5&R6