计算机系统概论课后练习答案第十章

F.10Chapter10Solutions
10.1The defining characteristic of a stack is the unique specification of how it is to be accessed.
Stack is a LIFO(Last in First Out)structure.This means that the last thing that is put in the
stack will be thefirst one to get out from the stack.
10.2The entries in the model in Figure10.2actually move when other entries are pushed and
popped,while they do not in the model of Figure10.3.If the stack is implemented in memory,
it makes more sense to access the one entry alone,plus the stack pointer,rather than access
all entries on the stack.If the stack is implemented as a piece of tailored logic,it is faster to
physically move the actual entries–provided that the power required to do so can handle it.
But that is a subject for a later course.
10.3(a)PUSH R1
(b)POP R0
(c)PUSH R3
(d)POP R7
10.4This routine copies the value of thefirst element on stack into R0.If underflow occurs,R5
is set to1(failure)else R5remains0(success).Overflow error checking is not necessary
because we are not adding anything to the stack.
PEEK AND R5,R5,#0;initialize R5
LEA R0,StackBase
NOT R0,R0
ADD R0,R0,#-1;R0=-(addr of
;stackbase+1)
ADD R0,R0,R6;R6-stack pointer
BRZ Underflow
LDR R0,R6,#0;put the first
;element in R0
RET
Underflow ADD R5,R5,#1;failure
RET
StackMax.BLKW10,x0000
StackBase.FILL x0000
10.5One way to check for overflow and underflow conditions is to keep track of a pointer that
tracks the bottom of the stack.This pointer can be compared with the address of thefirst and
last addresses of the space allocated for the stack.
;
;Subroutines for carrying out the PUSH and POP functions.This ;program works with a stack consisting of memory locations x3FFF ;(BASE)through x3FFB(MAX).R6is the bottom of the stack.
1
2
;
POP ST R1,Save1;are needed by POP.
ST R2,Save2
ST R3,Save3
LD R1,NBASE;BASE contains-x3FFF.
ADD R1,R1,#-1;R1contains-x4000.
ADD R2,R6,R1;Compare bottom of stack to x4000
BRz fail_exit;Branch if stack is empty.
LD R1,BASE;Iterate from the top of
;the stack
LDI R0,BASE;Load the value from the
NOT R3,R6;top of stack
ADD R3,R3,#1;Generate the晶振封装
;negative of the
;bottom-of-stack pointer
ADD R6,R6,#1;Increment the
;bottom-of-stack
;
pointer
机器人拉车pop_loop ADD R2,R1,R3;Compare iterating
;pointer to
;bottom-of-stack pointer
BRz success_exit;Branch if no more
;entries to shift
LDR R2,R1,#-1;Load the entry to shift
STR R2,R1,#0;Shift the entry
莫氏变径套ADD R1,R1,#-1;Increment the
;iterating pointer
BRnzp pop_loop
PUSH ST R1,Save1;Save registers that
ST R2,Save2;are needed by PUSH.
ST R3,Save3
LD R1,MAX;MAX contains-x3FFB
ADD R2,R6,R1;Compare stack pointer to-x3FFB
BRz fail_exit;Branch if stack is full.
ADD R1,R6,#0;Iterate from the bottom
;of stack
LD R3,NBASE;NBASE contains
;-x3FFF
ADD R3,R3,#-1;R3=-x4000
F.10.CHAPTER10SOLUTIONS3
push_loop ADD R2,R1,R3;Compare iterating
;pointer to
;bottom-of-stack pointer
BRz push_entry;Branch if no more
;entries to shift
LDR R2,R1,#0;Load the entry to shift
STR R2,R1,#-1;Shift the entry
ADD R1,R1,#1;Decrement the
;iterating pointer
BRnzp push_loop
push_entry ADD R6,R6,#-1;Increment the
;bottom-of-stack pointer
STI R0,BASE;Push a value onto stack
BRnzp success_exit
success_exit LD R1,Save1;Restore original
空调温度控制器LD R2,Save2;register values
LD R3,Save3
AND R5,R5,#0;R5<---success
RET
fail_exit LD R1,Save1;Restore original
LD R2,Save2;register values
LD R3,Save3
AND R5,R5,#0
ADD R5,R5,#1;R5<---failure
RET
BASE.FILL x3FFF
NBASE.FILL xC001;NBASE contains-x3FFF.
MAX.FILL xC005
Save1.FILL x0000
Save2.FILL x0000
Save3.FILL x0000
10.6This routine pushes the values in R0and R1onto the stack.R5is set to0if operation is
successful.If overflow occurs R5is set to1.This routine works with a stack consisting of memory locations x3FFF(BASE)to x3FFA(MAX).
PUSH ST R2,SaveR2
LD R2,MAX
NOT R2,R2
4
ADD R2,R2,#1;R2=-addr of stackmax
ADD R2,R6,R2
BRz Failure
STR R0,R6,#-1
STR R1,R6,#-2
ADD R6,R6,#-2
AND R5,R5,#0
LD R2,SaveR2
RET
Failure AND R5,R5,#0
ADD R5,R5,#1
LD R2,SaveR2
RET
MAX.FILL x3FFA
SaveR2.FILL x0000
This routine pops the top two elements of the stack into R0and R1.R5is set to0if the
operation is successful.If underflow occurs R5is set to1.This routine works with a stack
consisting of memory locations x3FFF(BASE)to x3FFA(MAX).
POP ST R2,SaveR2
LD R2,EMPTY;EMPTY<---x4000
ADD R2,R6,R2
BRz Failure;Underflow
LDR R1,R6,#0;Pop the first value
LDR R0,R6,#1;Pop the second value
ADD R6,R6,#2
AND R5,R5,#0
RET
Failure AND R5,R5,#0
ADD R5,R5,#1
RET
EMPTY.FILL xC000
SaveR2.FILL x0000
10.7;Subroutines for carrying out the PUSH and POP functions.This
;program works with a stack consisting of memory locations x3FFF ;(BASE)through x3FFB(MAX).R6is the stack pointer.R3contains ;the size of the stack element.R4is a pointer specifying the
;location of the element to PUSH from or the space to POP to
;
F.10.CHAPTER10SOLUTIONS5
POP ST R2,Save2;are needed by POP.
光工作站
ST R1,Save1
ST R0,Save0
LD R1,BASE;BASE contains-x3FFF.
ADD R1,R1,#-1;R1contains-x4000.
ADD R2,R6,R1;Compare stack pointer to x4000
BRz fail_exit;Branch if stack is empty.
ADD R0,R4,#0
ADD R1,R3,#0
ADD R5,R6,R3
ADD R5,R5,#-1
ADD R6,R6,R3
pop_loop LDR R2,R5,#0
STR R2,R0,#0
ADD R0,R0,#1
ADD R5,R5,#-1
ADD R1,R1,#-1
BRp pop_loop
BRnzp success_exit
PUSH ST R2,Save2;Save registers that
ST R1,Save1;are needed by PUSH.
ST R0,Save0
LD R1,MAX;MAX contains-x3FFB
ADD R2,R6,R1;Compare stack pointer to-x3FFB
BRz fail_exit;Branch if stack is full.
多媒体集中控制器
ADD R0,R4,#0
ADD R1,R3,#0
ADD R5,R6,#-1
NOT R2,R3
ADD R2,R2,#1
ADD R6,R6,R2
push_loop LDR R2,R0,#0
STR R2,R5,#0
ADD R0,R0,#1
ADD R5,R5,#-1
ADD R1,R1,#-1
BRp push_loop
success_exit LD R0,Save0
LD R1,Save1;Restore original
LD R2,Save2;register values.

本文发布于:2024-09-23 08:26:54,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/283922.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:控制器   晶振   机器人
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议