Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING PEP 8- PEP8 can be downloaded from : http://computersystemsbook.com/4th-ed

ID: 3869382 • Letter: U

Question

USING PEP 8- PEP8 can be downloaded from : http://computersystemsbook.com/4th-edition/pep8/

Create a program named while.pep and write an assembly language program to simulate execution of a C++ while loop statement. On startup the program will ask for a condition value ( 1 variable ).

You will need another variable that will start at zero and increment by one every time through the loop.The loop continues as long as this variable is strictly less than the condition and the loops ends if the variable is greater than or equal to this value.Inside the loop print the message "-loop value- inside the loop is Less Than -condition value-".After the loop completes print the message "Loop done, -loop value- equal or exceeds -condition value-".

You will, of course, insert the proper values for -loop value- and -condition value- and not print those exact words.

Be sure to lay out the logic (or flow) of the assembly program to match a while loop and use comments through out the code. In other words, clearly label in the code where each portion of the while loop starts and ends (this is an example, you should comment more):

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

USING PEP 8- PEP8 can be downloaded from : http://computersystemsbook.com/4th-edition/pep8/

Create a program named switch.pep and write an assembly language program to simulate execution of a C++ switch statement. On startup the program will ask for a input value from 0 to 4 ( 1 variable ).

The switch will select a case from 0 to 4 and have a default case. Assume each case has a break at the end.Inside each switch case print the message "-input value- inside the switch matches -case value-". In the default case print the input value and a message that is not 0 to 4.After the switch completes print the message "switch done".

You will, of course, insert the proper values for -input value- and -switch value- and not print those exact words.

Be sure to lay out the logic (or flow) of the assembly program to match a switch statement and use comments through out the code. In other words, clearly label in the code where each portion of the switch starts and ends (this is an example, you should comment more):

Explanation / Answer

While.pep: Program to simulate while loop in PEP8

num: .EQUATE 0 ;local variable
main: LDA 0,i
SUBSP 2,i ;allocate #num
LDA 5,i
STA num,s ;int num = 0;
while1: LDA 0,i ;while(1){
LDA num,s ;load num
ADDA 1,i ;num++
STA num,s ;store the value
STRO msg1,d ;cout << 'Result';
DECO num,s ;output the num variable
CHARO ' ',i ;<< endl
BR while1 ;}

STRO msg2,d ; After end of the while loop, displays message


msg1: .ASCII " -loop value- inside the loop is Less Than -condition value- "

msg2: .ASCII " Loop done, -loop value- equal or exceeds -condition value-"

.END

switch.Pep: Program to simulate SWITCH in PEP8

input: .block 2 ;global variable
main: NOP0
deci input,d ;get input
ldx input,d ;prepare for a switch-style jump
cpx 0,i ;if below valid input range
brlt makedef,i
cpx 4,i ;if above valid input range
brgt makedef,i
br swmain,i
makedef: nop0
ldx swdeflt,i ;load location of default to index register, overriding loaded user input
swmain: nop0
aslx ;convert from index to offset
br loctns,x ;continue execution at the address listed in loctns[X]

zero: stro msg,d ; output cmsg

br donecase i

first: stro msg,d ;output cmsg

br donecase, i
second: stro mesg,d ;output cmsg
br donecase,i   
third: stro msg,d ;output switch message cmsg
br donecase,i

fourth: stro msg,d ; output switch message cmsg

br donecase , i
default: stro dmsg,d ;output default message
br donecase,i
donecase: nop0 ;done with the switch statement
charo ' ',i ;prettify output

stro emsg,d ; output switch done

;Strings
cmsg: .ascii " -input value- inside the switch matches -case value-"
dmsg: .ascii " Given input is not in range of 0 to 4"

emsg:.ascii" switch done"

swdeflt: .equate 0 ;offset of default for this switch


.END