{"id":79028,"date":"2021-12-02T18:07:27","date_gmt":"2021-12-02T18:07:27","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/wtm-push-demo-csc240-fall-2014-commands-x\/"},"modified":"2021-12-02T18:07:27","modified_gmt":"2021-12-02T18:07:27","slug":"wtm-push-demo-csc240-fall-2014-commands-x","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/wtm-push-demo-csc240-fall-2014-commands-x\/","title":{"rendered":"; WTM Push Demo CSC240 Fall 2014 ; Commands: ; X &#8211;"},"content":{"rendered":"<p>; WTM Push Demo CSC240 Fall 2014<\/p>\n<p> ; Commands: <\/p>\n<p> ; X &#8211; Exit the program. <\/p>\n<p> ; D &#8211; Pop and display value at top of stack. <\/p>\n<p> ; XXX integer + ENTER &#8211; Push value onto stack<\/p>\n<p> .ORIG x3000<\/p>\n<p> ;<\/p>\n<p> ;<\/p>\n<p> LEA R6,StackBase ; Initialize the Stack.<\/p>\n<p> ADD R6,R6,#0 ; R6 is stack pointer<\/p>\n<p> LEA R0,PromptMsg<\/p>\n<p> PUTS<\/p>\n<p> GETC<\/p>\n<p> OUT<\/p>\n<p> Test LD R1,NegX ; Check for X entered <\/p>\n<p> ADD R1,R1,R0<\/p>\n<p> BRz Exit<\/p>\n<p> ;<\/p>\n<p> LD R1,NegC ; Check for C entered <\/p>\n<p> ADD R1,R1,R0<\/p>\n<p> BRz OpClear ; See Figure 10.27 page 283<\/p>\n<p> ;<\/p>\n<p> LD R1,NegD ; Check for D entered <\/p>\n<p> ADD R1,R1,R0<\/p>\n<p> BRz OpDisplay ; <\/p>\n<p> ;<\/p>\n<p> ; Then, user must have entered a value<\/p>\n<p> BRnzp PushValue ; See Figure 10.25 page 282<\/p>\n<p> ;<\/p>\n<p> NewCommand LEA R0,PromptMsg<\/p>\n<p> PUTS<\/p>\n<p> GETC<\/p>\n<p> OUT<\/p>\n<p> BRnzp Test<\/p>\n<p> Exit HALT<\/p>\n<p> PromptMsg .FILL x000A<\/p>\n<p> .STRINGZ &#8220;Enter a command or an integer:&#8221;<\/p>\n<p> NegX .FILL xFFA8<\/p>\n<p> NegC .FILL xFFBD<\/p>\n<p> NegD .FILL xFFBC<\/p>\n<p> NegP .FILL xFFB0<\/p>\n<p> ; This algorithm takes a sequence of ASCII digits typed by the user, <\/p>\n<p> ; converts it into a binary value by calling the ASCIItoBinary <\/p>\n<p> ; subroutine and pushes the binary value onto the stack. <\/p>\n<p> ; <\/p>\n<p> PushValue LEA R1,ASCIIBUFF ; R1 points to string being <\/p>\n<p> LD R2,MaxDigits ; generated<\/p>\n<p> ;<\/p>\n<p> ValueLoop ADD R3,R0,xFFF6 ; Test for carriage return<\/p>\n<p> BRz GoodInput<\/p>\n<p> ADD R2,R2,#0<\/p>\n<p> BRz TooLargeInput<\/p>\n<p> ADD R2,R2,#-1 ; Still room for more digits<\/p>\n<p> STR R0,R1,#0 ; Store last character read<\/p>\n<p> ADD R1,R1,#1 <\/p>\n<p> GETC<\/p>\n<p> OUT ; Echo it<\/p>\n<p> BRnzp ValueLoop<\/p>\n<p> ;<\/p>\n<p> GoodInput LEA R2,ASCIIBUFF<\/p>\n<p> NOT R2,R2<\/p>\n<p> ADD R2,R2,#1<\/p>\n<p> ADD R1,R1,R2 ; R1 now contains no. of char.<\/p>\n<p> JSR ASCIItoBinary<\/p>\n<p> JSR PUSH<\/p>\n<p> BRnzp NewCommand<\/p>\n<p> ;<\/p>\n<p> TooLargeInput GETC ; Spin until carriage return<\/p>\n<p> OUT<\/p>\n<p> ADD R3,R0,xFFF6<\/p>\n<p> BRnp TooLargeInput<\/p>\n<p> LEA R0,TooManyDigits<\/p>\n<p> PUTS<\/p>\n<p> BRnzp NewCommand<\/p>\n<p> TooManyDigits .FILL x000A<\/p>\n<p> .STRINGZ &#8220;Too many digits&#8221;<\/p>\n<p> MaxDigits .FILL x0003<\/p>\n<p> ;<\/p>\n<p> ; This routine clears the stack by resetting the stack pointer (R6).<\/p>\n<p> ;<\/p>\n<p> OpClear LEA R6,StackBase ; Initialize the Stack.<\/p>\n<p> ADD R6,R6,#1 ; R6 is stack pointer<\/p>\n<p> BRnzp NewCommand<\/p>\n<p> ;<\/p>\n<p> ; Routine to pop the top two elements from the stack,<\/p>\n<p> ; add them, and push the sum onto the stack. R6 is<\/p>\n<p> ; the stack pointer.<\/p>\n<p> ;<\/p>\n<p> ;<\/p>\n<p> ; Routine to check that the magnitude of a value is <\/p>\n<p> ; between -999 and +999.<\/p>\n<p> ;<\/p>\n<p> RangeCheck LD R5,Neg999<\/p>\n<p> ADD R4,R0,R5 ; Recall that R0 contains the <\/p>\n<p> BRp BadRange ; result being checked.<\/p>\n<p> LD R5,Pos999<\/p>\n<p> ADD R4,R0,R5<\/p>\n<p> BRn BadRange<\/p>\n<p> AND R5,R5,#0 ; R5 &lt;&#8211; success<\/p>\n<p> RET<\/p>\n<p> BadRange ST R7,Save ; R7 is needed by TRAP\/RET<\/p>\n<p> LEA R0,RangeErrorMsg<\/p>\n<p> TRAP x22 ; Output character string<\/p>\n<p> LD R7,Save<\/p>\n<p> AND R5,R5,#0 ; <\/p>\n<p> ADD R5,R5,#1 ; R5 &lt;&#8211; failure<\/p>\n<p> RET<\/p>\n<p> Neg999 .FILL #-999<\/p>\n<p> Pos999 .FILL #999<\/p>\n<p> Save .FILL x0000<\/p>\n<p> RangeErrorMsg .FILL x000A<\/p>\n<p> .STRINGZ &#8220;Error: Number is out of range.&#8221;<\/p>\n<p> ;<\/p>\n<p> ; This algorithm calls BinarytoASCII to convert the 2&#8217;s complement <\/p>\n<p> ; number on the top of the stack into an ASCII character string, and<\/p>\n<p> ; then calls PUTS to display that number on the screen.<\/p>\n<p> OpDisplay JSR POP ; R0 gets the value to be displayed<\/p>\n<p> ADD R5,R5,#0 <\/p>\n<p> BRp NewCommand ; POP failed, nothing on the stack.<\/p>\n<p> JSR BinarytoASCII <\/p>\n<p> LD R0,NewlineChar<\/p>\n<p> OUT<\/p>\n<p> LEA R0,ASCIIBUFF<\/p>\n<p> PUTS<\/p>\n<p> ;ADD R6,R6,#0 ; Push displayed number back on stack<\/p>\n<p> BRnzp NewCommand<\/p>\n<p> NewlineChar .FILL x000A<\/p>\n<p> ASCIIBUFF .BLKW 4<\/p>\n<p> BUFFEREND .FILL x0000 ; needed to force x0000 at end of ASCIIBUFF<\/p>\n<p> ;<\/p>\n<p> ; This algorithm POPs a value from the stack and puts it in<\/p>\n<p> ; R0 before returning to the calling program. R5 is used to<\/p>\n<p> ; report success (R5=0) or failure (R5=1) of the POP operation.<\/p>\n<p> POP LEA R0,StackBase<\/p>\n<p> NOT R0,R0<\/p>\n<p> ADD R0,R0,#1 ; R0 = -(addr.ofStackBase -1)<\/p>\n<p> ADD R0,R0,R6 ; R6 = StackPointer<\/p>\n<p> BRz Underflow<\/p>\n<p> LDR R0,R6,#0 ; The actual POP <\/p>\n<p> ADD R6,R6,#1 ; Adjust StackPointer<\/p>\n<p> AND R5,R5,#0 ; R5 &lt;&#8211; success<\/p>\n<p> RET <\/p>\n<p> Underflow ST R7,SaveR7 ; TRAP\/RET needs R7<\/p>\n<p> LEA R0,UnderflowMsg<\/p>\n<p> PUTS ; Print error message.<\/p>\n<p> LD R7,SaveR7 ; Restore R7<\/p>\n<p> AND R5,R5,#0 <\/p>\n<p> ADD R5,R5,#1 ; R5 &lt;&#8211; failure<\/p>\n<p> RET<\/p>\n<p> SaveR7 .FILL x0000<\/p>\n<p> StackMax .BLKW 9<\/p>\n<p> StackBase .FILL x0000<\/p>\n<p> UnderflowMsg .FILL x000A<\/p>\n<p> .STRINGZ &#8220;Error: Too Few Values on the Stack.&#8221;<\/p>\n<p> ; This algorithm PUSHes on the stack the value stored in R0.<\/p>\n<p> ; R5 is used to report success (R5=0) or failure (R5=1) of <\/p>\n<p> ; the PUSH operation.<\/p>\n<p> ;<\/p>\n<p> PUSH ST R1,Save1 ; R1 is needed by this routine<\/p>\n<p> LEA R1,StackMax<\/p>\n<p> NOT R1,R1<\/p>\n<p> ADD R1,R1,#1 ; R1 = &#8211; addr. of StackMax <\/p>\n<p> ADD R1,R1,R6 ; R6 = StackPointer<\/p>\n<p> BRz Overflow<\/p>\n<p> ADD R6,R6,#-1 ; Adjust StackPointer for PUSH<\/p>\n<p> STR R0,R6,#0 ; The actual PUSH<\/p>\n<p> BRnzp Success_exit<\/p>\n<p> Overflow ST R7,Save7PUSH<\/p>\n<p> LEA R0,OverflowMsg<\/p>\n<p> PUTS<\/p>\n<p> LD R7,Save7PUSH<\/p>\n<p> LD R1, Save1 ; Restore R1<\/p>\n<p> AND R5,R5,#0 <\/p>\n<p> ADD R5,R5,#1 ; R5 &lt;&#8211; failure<\/p>\n<p> RET<\/p>\n<p> Success_exit LD R1,Save1 ; Restore R1<\/p>\n<p> AND R5,R5,#0 ; R5 &lt;&#8211; success<\/p>\n<p> RET<\/p>\n<p> Save7PUSH .FILL x0000<\/p>\n<p> Save1 .FILL x0000<\/p>\n<p> OverflowMsg .STRINGZ &#8220;Error: Stack is Full.&#8221;<\/p>\n<p> ;<\/p>\n<p> ; This algorithm takes an ASCII string of three decimal digits and <\/p>\n<p> ; converts it into a binary number. R0 is used to collect the result.<\/p>\n<p> ; R1 keeps track of how many digits are left to process. ASCIIBUFF<\/p>\n<p> ; contains the most significant digit in the ASCII string.<\/p>\n<p> ;<\/p>\n<p> ASCIItoBinary AND R0,R0,#0 ; R0 will be used for our result <\/p>\n<p> ADD R1,R1,#0 ; Test number of digits.<\/p>\n<p> BRz DoneAtoB ; There are no digits<\/p>\n<p> ;<\/p>\n<p> LD R3,NegASCIIOffset ; R3 gets xFFD0, i.e., -x0030<\/p>\n<p> LEA R2,ASCIIBUFF<\/p>\n<p> ADD R2,R2,R1<\/p>\n<p> ADD R2,R2,#-1 ; R2 now points to &#8220;ones&#8221; digit<\/p>\n<p> ; <\/p>\n<p> LDR R4,R2,#0 ; R4 &lt;&#8211; &quot;ones&quot; digit<\/p>\n<p> ADD R4,R4,R3 ; Strip off the ASCII template<\/p>\n<p> ADD R0,R0,R4 ; Add ones contribution<\/p>\n<p> ;<\/p>\n<p> ADD R1,R1,#-1<\/p>\n<p> BRz DoneAtoB ; The original number had one digit<\/p>\n<p> ADD R2,R2,#-1 ; R2 now points to &#8220;tens&#8221; digit<\/p>\n<p> ;<\/p>\n<p> LDR R4,R2,#0 ; R4 &lt;&#8211; &quot;tens&quot; digit<\/p>\n<p> ADD R4,R4,R3 ; Strip off ASCII template<\/p>\n<p> LEA R5,LookUp10 ; LookUp10 is BASE of tens values<\/p>\n<p> ADD R5,R5,R4 ; R5 points to the right tens value<\/p>\n<p> LDR R4,R5,#0<\/p>\n<p> ADD R0,R0,R4 ; Add tens contribution to total<\/p>\n<p> ;<\/p>\n<p> ADD R1,R1,#-1<\/p>\n<p> BRz DoneAtoB ; The original number had two digits<\/p>\n<p> ADD R2,R2,#-1 ; R2 now points to &#8220;hundreds&#8221; digit<\/p>\n<p> ; <\/p>\n<p> LDR R4,R2,#0 ; R4 &lt;&#8211; &quot;hundreds&quot; digit<\/p>\n<p> ADD R4,R4,R3 ; Strip off ASCII template<\/p>\n<p> LEA R5,LookUp100 ; LookUp100 is hundreds BASE<\/p>\n<p> ADD R5,R5,R4 ; R5 points to hundreds value<\/p>\n<p> LDR R4,R5,#0<\/p>\n<p> ADD R0,R0,R4 ; Add hundreds contribution to total<\/p>\n<p> ; <\/p>\n<p> DoneAtoB RET<\/p>\n<p> NegASCIIOffset .FILL xFFD0<\/p>\n<p> LookUp10 .FILL #0<\/p>\n<p> .FILL #10<\/p>\n<p> .FILL #20<\/p>\n<p> .FILL #30<\/p>\n<p> .FILL #40<\/p>\n<p> .FILL #50<\/p>\n<p> .FILL #60<\/p>\n<p> .FILL #70<\/p>\n<p> .FILL #80<\/p>\n<p> .FILL #90<\/p>\n<p> ;<\/p>\n<p> LookUp100 .FILL #0<\/p>\n<p> .FILL #100<\/p>\n<p> .FILL #200<\/p>\n<p> .FILL #300<\/p>\n<p> .FILL #400<\/p>\n<p> .FILL #500<\/p>\n<p> .FILL #600<\/p>\n<p> .FILL #700<\/p>\n<p> .FILL #800<\/p>\n<p> .FILL #900<\/p>\n<p> ;<\/p>\n<p> ; This algorithm takes the 2&#8217;s complement representation of a signed<\/p>\n<p> ; integer, within the range -999 to +999, and converts it into an ASCII <\/p>\n<p> ; string consisting of a sign digit, followed by three decimal digits. <\/p>\n<p> ; R0 contains the initial value being converted.<\/p>\n<p> ;<\/p>\n<p> BinarytoASCII LEA R1,ASCIIBUFF ; R1 points to string being generated<\/p>\n<p> ADD R0,R0,#0 ; R0 contains the binary value<\/p>\n<p> BRn NegSign ; <\/p>\n<p> LD R2,ASCIIplus ; First store the ASCII plus sign<\/p>\n<p> STR R2,R1,#0<\/p>\n<p> BRnzp Begin100<\/p>\n<p> NegSign LD R2,ASCIIminus ; First store ASCII minus sign<\/p>\n<p> STR R2,R1,#0<\/p>\n<p> NOT R0,R0 ; Convert the number to absolute<\/p>\n<p> ADD R0,R0,#1 ; value; it is easier to work with.<\/p>\n<p> ;<\/p>\n<p> Begin100 LD R2,ASCIIoffset ; Prepare for &#8220;hundreds&#8221; digit<\/p>\n<p> ;<\/p>\n<p> LD R3,Neg100 ; Determine the hundreds digit<\/p>\n<p> Loop100 ADD R0,R0,R3<\/p>\n<p> BRn End100<\/p>\n<p> ADD R2,R2,#1<\/p>\n<p> BRnzp Loop100<\/p>\n<p> ;<\/p>\n<p> End100 STR R2,R1,#1 ; Store ASCII code for hundreds digit<\/p>\n<p> LD R3,Pos100<\/p>\n<p> ADD R0,R0,R3 ; Correct R0 for one-too-many subtracts<\/p>\n<p> ;<\/p>\n<p> LD R2,ASCIIoffset ; Prepare for &#8220;tens&#8221; digit<\/p>\n<p> ;<\/p>\n<p> Begin10 LD R3,Neg10 ; Determine the tens digit<\/p>\n<p> Loop10 ADD R0,R0,R3<\/p>\n<p> BRn End10<\/p>\n<p> ADD R2,R2,#1<\/p>\n<p> BRnzp Loop10<\/p>\n<p> ;<\/p>\n<p> End10 STR R2,R1,#2 ; Store ASCII code for tens digit <\/p>\n<p> ADD R0,R0,#10 ; Correct R0 for one-too-many subtracts<\/p>\n<p> Begin1 LD R2,ASCIIoffset ; Prepare for &#8220;ones&#8221; digit<\/p>\n<p> ADD R2,R2,R0<\/p>\n<p> STR R2,R1,#3<\/p>\n<p> RET<\/p>\n<p> ;<\/p>\n<p> ASCIIplus .FILL x002B<\/p>\n<p> ASCIIminus .FILL x002D<\/p>\n<p> ASCIIoffset .FILL x0030<\/p>\n<p> Neg100 .FILL xFF9C<\/p>\n<p> Pos100 .FILL x0064<\/p>\n<p> Neg10 .FILL xFFF6<\/p>\n<p> .END ; end of assembly listing<\/p>\n","protected":false},"excerpt":{"rendered":"<p>; WTM Push Demo CSC240 Fall 2014 ; Commands: ; X &#8211; Exit the program. ; D &#8211; Pop and display value at top of stack. ; XXX integer + ENTER &#8211; Push value onto stack .ORIG x3000 ; ; LEA R6,StackBase ; Initialize the Stack. ADD R6,R6,#0 ; R6 is stack pointer LEA R0,PromptMsg [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-79028","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=79028"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79028\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=79028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=79028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=79028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}