1 ( EG00.ASM - one can't avoid this one! ) 2 3 "Hello world" 4 5 HALT 6 7 (----------------------------------------------------------) 8 9 ( EG01.ASM - example showing reverse polish expression evaluation ) 10 11 40 5 + 3 * . ( should print 135 ) 12 13 HALT 14 15 (----------------------------------------------------------) 16 17 ( EG02.ASM - will divide by zero and crash ) 18 19 VARIABLE A VARIABLE B VARIABLE C 20 21 C A @ B @ / ! ( c = a / b ) 22 23 HALT 24 25 (----------------------------------------------------------) 26 27 ( EG03.ASM - store and retrieve a variable ) 28 29 VARIABLE MeaningOfLife 30 31 MeaningOfLife 42 ! 32 33 "The Meaning Of Life is " 34 35 MeaningOfLife @ . 36 37 HALT 38 39 (----------------------------------------------------------) 40 41 ( EG04.ASM - some variables and constants ) 42 43 VARIABLE x 44 CONSTANT pi 22 45 46 pi . ( should print 22 ) 47 48 x pi ! ( x should now be 22 ) 49 50 x @ x @ * . ( should display 484 ) 51 52 HALT 53 54 (----------------------------------------------------------) 55 56 ( EG05.ASM - simple tests of logical operations ) 57 58 true false and .B ( should display false ) 59 60 true true and .B ( should display true ) 61 62 false true or .B ( should display true ) 63 64 false not .B ( should display true ) 65 66 HALT 67 68 (----------------------------------------------------------) 69 70 ( EG06.ASM - simple tests of DUP and ABS words ) 71 ( note that we can write really silly code to test these 72 operations; we do not need meaningful programs! ) 73 74 3 dup * . ( should display 9 ) 75 cr ( new line ) 76 77 -56 abs . ( should display 56 ) 78 cr ( new line ) 79 80 HALT 81 82 (----------------------------------------------------------) 83 84 ( EG07.ASM - simple tests of character operations ) 85 86 VARIABLE ch 87 88 ch ?c ( read ch ) 89 ch @ . ( should display ascii value for character just read ) 90 cr ( new line ) 91 ch @ .c ( should echo character read ) 92 93 "\nLess than Z? " 94 ch @ 'Z' < .b ( will display true if character read was less than 'Z' ) 95 96 "\nLetter/digit? " 97 ch @ ISLD .b ( will display true if it was a letter or digit ) 98 99 "\nUppercase equivalent " 100 ch @ CAP .c ( should display upper case equivalent of character read ) 101 102 HALT 103 104 (----------------------------------------------------------) 105 106 ( EG08.ASM - simple tests of ++ and -- ) 107 108 VARIABLE A 109 110 A 12 ! A ++ A @ . ( should display 13 ) 111 112 A 25 ! A -- A @ . ( should display 24 ) 113 114 HALT 115 116 (----------------------------------------------------------) 117 118 ( EG09.ASM - test some escape sequences ) 119 120 ( 1 2 3 4 121 Hello 122 dear 123 world 124 ) 125 126 "1\t2\t3\t4\nHello\ndear\nworld" 127 128 HALT 129 130 (----------------------------------------------------------) 131 132 ( EG10.ASM - test some array operations ) 133 134 VARIABLE list VARIABLE index 135 136 list 3 new ! ( Allocate space for small array ) 137 138 "supply subscript 0 - 2 or larger to break it " 139 index ? ( read index ) 140 141 list @ index @ [] 45 ! ( list[index] = 45 ) 142 list @ index @ [] ++ ( list[index]++ ) 143 list @ index @ [] @ . ( should display 46 ) 144 145 HALT 146 147 (----------------------------------------------------------) 148 149 ( EG11.ASM - simple IF statement - deeply significant, no doubt ) 150 151 VARIABLE age 152 age ? ( read age ) 153 154 age @ 60 > IF ( if ( age > 60 ) ) 155 "Is the meaning of life really " 42 . ( write("Is the meaning of life really ", 42) ) 156 ENDIF 157 158 HALT 159 160 (----------------------------------------------------------) 161 162 ( EG12.ASM - a silly sequence for testing the if - endif construct ) 163 164 true 165 if 166 "You should see this message first and nothing more" 167 endif 168 169 false 170 if 171 "If you see this there is a problem in your compiler" 172 endif 173 174 HALT 175 176 (----------------------------------------------------------) 177 178 ( EG13.ASM - Form the sum of a list of numbers terminated with zero ) 179 180 VARIABLE x VARIABLE Total 181 182 Total 0 ! ( Total = 0 ) 183 184 REPEAT 185 x ? ( Read(x) ) 186 Total x @ Total @ + ! ( Total = x + Total ) 187 x @ 0 == ( x == 0 ? ) 188 UNTIL 189 190 "Total is" Total @ . ( write ("Total is" , Total) ) 191 192 HALT 193 194 (----------------------------------------------------------) 195 196 ( EG14.ASM - simple repeat loop ) 197 198 VARIABLE x 199 200 repeat ( read list and reflect absolute values ) 201 x ? 202 x @ abs . 203 cr 204 x @ 205 0 == 206 until 207 208 HALT 209 210 (----------------------------------------------------------) 211 212 ( EG15.ASM - the STK word is a useful one for inspecting the stack ) 213 214 1 2 3 4 5 6 7 8 9 10 STK ( 10 elements ) 215 + + + STK ( 7 elements - top value is now 10+9+8+7 = 34 ) 216 217 HALT 218 219 (----------------------------------------------------------) 220 221 ( EG16.ASM - an upper case conversion without CAP ) 222 223 VARIABLE ch 224 225 repeat ( repeat ) 226 ch ?c ( read(ch); ) 227 ch @ 228 dup 'a' >= 229 if dup 'z' <= 230 if 32 - endif 231 endif 232 .c ( display CAP(ch) ) 233 ch @ '.' == ( until (ch == '.') ; ) 234 until 235 236 HALT 237 238 (----------------------------------------------------------) 239 240 ( EG17.ASM - truth tables and nested loops ) 241 242 VARIABLE x VARIABLE y 243 244 " x y x & y x | y" cr cr 245 246 x false ! y false ! 247 248 repeat 249 repeat 250 x @ .b 251 y @ .b 252 x @ y @ and .b 253 x @ y @ or .b 254 cr 255 y y @ not ! y @ not 256 until 257 x x @ not ! x @ not 258 until 259 260 HALT 261 262 (----------------------------------------------------------) 263 1 File: eg00.pvm 2 3 ASSEM 4 BEGIN 5 { 0 } DSP 0 6 { 2 } PRNS "Hello world" 7 { 4 } HALT 8 END. 9 10 ------------------------------ 11 12 File: eg01.pvm 13 14 ASSEM 15 BEGIN 16 { 0 } DSP 0 17 { 2 } LDC 40 18 { 4 } LDC 5 19 { 6 } ADD 20 { 7 } LDC 3 21 { 9 } MUL 22 { 10 } PRNI 23 { 11 } HALT 24 END. 25 26 ------------------------------ 27 28 File: eg02.pvm 29 30 ASSEM 31 BEGIN 32 { 0 } DSP 3 33 { 2 } LDA 2 34 { 4 } LDA 0 35 { 6 } LDV 36 { 7 } LDA 1 37 { 9 } LDV 38 { 10 } DIV 39 { 11 } STO 40 { 12 } HALT 41 END. 42 43 ------------------------------ 44 45 File: eg03.pvm 46 47 ASSEM 48 BEGIN 49 { 0 } DSP 1 50 { 2 } LDA 0 51 { 4 } LDC 42 52 { 6 } STO 53 { 7 } PRNS "The Meaning Of Life is " 54 { 9 } LDA 0 55 { 11 } LDV 56 { 12 } PRNI 57 { 13 } HALT 58 END. 59 60 ------------------------------ 61 62 File: eg04.pvm 63 64 ASSEM 65 BEGIN 66 { 0 } DSP 1 67 { 2 } LDC 22 68 { 4 } PRNI 69 { 5 } LDA 0 70 { 7 } LDC 22 71 { 9 } STO 72 { 10 } LDA 0 73 { 12 } LDV 74 { 13 } LDA 0 75 { 15 } LDV 76 { 16 } MUL 77 { 17 } PRNI 78 { 18 } HALT 79 END. 80 81 ------------------------------ 82 83 File: eg05.pvm 84 85 ASSEM 86 BEGIN 87 { 0 } DSP 0 88 { 2 } LDC 1 89 { 4 } LDC 0 90 { 6 } AND 91 { 7 } PRNB 92 { 8 } LDC 1 93 { 10 } LDC 1 94 { 12 } AND 95 { 13 } PRNB 96 { 14 } LDC 0 97 { 16 } LDC 1 98 { 18 } OR 99 { 19 } PRNB 100 { 20 } LDC 0 101 { 22 } NOT 102 { 23 } PRNB 103 { 24 } HALT 104 END. 105 106 ------------------------------ 107 108 File: eg06.pvm 109 110 ASSEM 111 BEGIN 112 { 0 } DSP 0 113 { 2 } LDC 3 114 { 4 } DUP 115 { 5 } MUL 116 { 6 } PRNI 117 { 7 } PRNL 118 { 8 } LDC -56 119 { 10 } ABS 120 { 11 } PRNI 121 { 12 } PRNL 122 { 13 } HALT 123 END. 124 125 ------------------------------ 126 127 File: eg07.pvm 128 129 ASSEM 130 BEGIN 131 { 0 } DSP 1 132 { 2 } LDA 0 133 { 4 } INPC 134 { 5 } LDA 0 135 { 7 } LDV 136 { 8 } PRNI 137 { 9 } PRNL 138 { 10 } LDA 0 139 { 12 } LDV 140 { 13 } PRNC 141 { 14 } PRNS "\nLess than Z? " 142 { 16 } LDA 0 143 { 18 } LDV 144 { 19 } LDC 90 145 { 21 } CLT 146 { 22 } PRNB 147 { 23 } PRNS "\nLetter/digit? " 148 { 25 } LDA 0 149 { 27 } LDV 150 { 28 } ISLD 151 { 29 } PRNB 152 { 30 } PRNS "\nUppercase equivalent " 153 { 32 } LDA 0 154 { 34 } LDV 155 { 35 } CAP 156 { 36 } PRNC 157 { 37 } HALT 158 END. 159 160 ------------------------------ 161 162 File: eg08.pvm 163 164 ASSEM 165 BEGIN 166 { 0 } DSP 1 167 { 2 } LDA 0 168 { 4 } LDC 12 169 { 6 } STO 170 { 7 } LDA 0 171 { 9 } INC 172 { 10 } LDA 0 173 { 12 } LDV 174 { 13 } PRNI 175 { 14 } LDA 0 176 { 16 } LDC 25 177 { 18 } STO 178 { 19 } LDA 0 179 { 21 } DEC 180 { 22 } LDA 0 181 { 24 } LDV 182 { 25 } PRNI 183 { 26 } HALT 184 END. 185 186 ------------------------------ 187 188 File: eg09.pvm 189 190 ASSEM 191 BEGIN 192 { 0 } DSP 0 193 { 2 } PRNS "1\t2\t3\t4\nHello\ndear\nworld" 194 { 4 } HALT 195 END. 196 197 ------------------------------ 198 199 File: eg10.pvm 200 201 ASSEM 202 BEGIN 203 { 0 } DSP 2 204 { 2 } LDA 0 205 { 4 } LDC 3 206 { 6 } ANEW 207 { 7 } STO 208 { 8 } PRNS "supply subscript 0 - 2 or larger to break it " 209 { 10 } LDA 1 210 { 12 } INPI 211 { 13 } LDA 0 212 { 15 } LDV 213 { 16 } LDA 1 214 { 18 } LDV 215 { 19 } LDXA 216 { 20 } LDC 45 217 { 22 } STO 218 { 23 } LDA 0 219 { 25 } LDV 220 { 26 } LDA 1 221 { 28 } LDV 222 { 29 } LDXA 223 { 30 } INC 224 { 31 } LDA 0 225 { 33 } LDV 226 { 34 } LDA 1 227 { 36 } LDV 228 { 37 } LDXA 229 { 38 } LDV 230 { 39 } PRNI 231 { 40 } HALT 232 END. 233 234 ------------------------------ 235 236 File: eg11.pvm 237 238 ASSEM 239 BEGIN 240 { 0 } DSP 1 241 { 2 } LDA 0 242 { 4 } INPI 243 { 5 } LDA 0 244 { 7 } LDV 245 { 8 } LDC 60 246 { 10 } CGT 247 { 11 } BZE 18 248 { 13 } PRNS "Is the meaning of life really " 249 { 15 } LDC 42 250 { 17 } PRNI 251 { 18 } HALT 252 END. 253 254 ------------------------------ 255 256 File: eg12.pvm 257 258 ASSEM 259 BEGIN 260 { 0 } DSP 0 261 { 2 } LDC 1 262 { 4 } BZE 8 263 { 6 } PRNS "You should see this message first and nothing more" 264 { 8 } LDC 0 265 { 10 } BZE 14 266 { 12 } PRNS "If you see this there is a problem in your compiler" 267 { 14 } HALT 268 END. 269 270 ------------------------------ 271 272 File: eg13.pvm 273 274 ASSEM 275 BEGIN 276 { 0 } DSP 2 277 { 2 } LDA 1 278 { 4 } LDC 0 279 { 6 } STO 280 { 7 } LDA 0 281 { 9 } INPI 282 { 10 } LDA 1 283 { 12 } LDA 0 284 { 14 } LDV 285 { 15 } LDA 1 286 { 17 } LDV 287 { 18 } ADD 288 { 19 } STO 289 { 20 } LDA 0 290 { 22 } LDV 291 { 23 } LDC 0 292 { 25 } CEQ 293 { 26 } BZE 7 294 { 28 } PRNS "Total is" 295 { 30 } LDA 1 296 { 32 } LDV 297 { 33 } PRNI 298 { 34 } HALT 299 END. 300 301 ------------------------------ 302 303 File: eg14.pvm 304 305 ASSEM 306 BEGIN 307 { 0 } DSP 1 308 { 2 } LDA 0 309 { 4 } INPI 310 { 5 } LDA 0 311 { 7 } LDV 312 { 8 } ABS 313 { 9 } PRNI 314 { 10 } PRNL 315 { 11 } LDA 0 316 { 13 } LDV 317 { 14 } LDC 0 318 { 16 } CEQ 319 { 17 } BZE 2 320 { 19 } HALT 321 END. 322 323 ------------------------------ 324 325 File: eg15.pvm 326 327 ASSEM 328 BEGIN 329 { 0 } DSP 0 330 { 2 } LDC 1 331 { 4 } LDC 2 332 { 6 } LDC 3 333 { 8 } LDC 4 334 { 10 } LDC 5 335 { 12 } LDC 6 336 { 14 } LDC 7 337 { 16 } LDC 8 338 { 18 } LDC 9 339 { 20 } LDC 10 340 { 22 } STK 341 { 23 } ADD 342 { 24 } ADD 343 { 25 } ADD 344 { 26 } STK 345 { 27 } HALT 346 END. 347 348 ------------------------------ 349 350 File: eg16.pvm 351 352 ASSEM 353 BEGIN 354 { 0 } DSP 1 355 { 2 } LDA 0 356 { 4 } INPC 357 { 5 } LDA 0 358 { 7 } LDV 359 { 8 } DUP 360 { 9 } LDC 97 361 { 11 } CGE 362 { 12 } BZE 23 363 { 14 } DUP 364 { 15 } LDC 122 365 { 17 } CLE 366 { 18 } BZE 23 367 { 20 } LDC 32 368 { 22 } SUB 369 { 23 } PRNC 370 { 24 } LDA 0 371 { 26 } LDV 372 { 27 } LDC 46 373 { 29 } CEQ 374 { 30 } BZE 2 375 { 32 } HALT 376 END. 377 378 ------------------------------ 379 380 File: eg17.pvm 381 382 ASSEM 383 BEGIN 384 { 0 } DSP 2 385 { 2 } PRNS " x y x & y x | y" 386 { 4 } PRNL 387 { 5 } PRNL 388 { 6 } LDA 0 389 { 8 } LDC 0 390 { 10 } STO 391 { 11 } LDA 1 392 { 13 } LDC 0 393 { 15 } STO 394 { 16 } LDA 0 395 { 18 } LDV 396 { 19 } PRNB 397 { 20 } LDA 1 398 { 22 } LDV 399 { 23 } PRNB 400 { 24 } LDA 0 401 { 26 } LDV 402 { 27 } LDA 1 403 { 29 } LDV 404 { 30 } AND 405 { 31 } PRNB 406 { 32 } LDA 0 407 { 34 } LDV 408 { 35 } LDA 1 409 { 37 } LDV 410 { 38 } OR 411 { 39 } PRNB 412 { 40 } PRNL 413 { 41 } LDA 1 414 { 43 } LDA 1 415 { 45 } LDV 416 { 46 } NOT 417 { 47 } STO 418 { 48 } LDA 1 419 { 50 } LDV 420 { 51 } NOT 421 { 52 } BZE 16 422 { 54 } LDA 0 423 { 56 } LDA 0 424 { 58 } LDV 425 { 59 } NOT 426 { 60 } STO 427 { 61 } LDA 0 428 { 63 } LDV 429 { 64 } NOT 430 { 65 } BZE 16 431 { 67 } HALT 432 END. 433 434 ------------------------------ 435 1 ( EG101.asm - simple tests of swap, over and drop words ) 2 ( note that we can write really silly code to test these 3 operations; we do not need meaningful programs! ) 4 5 1 2 swap . . ( should display 1 2 ) 6 cr ( new line ) 7 8 stk ( should be empty ) 9 10 4 5 drop . ( should display 4 ) 11 cr ( new line ) 12 13 stk ( should be empty ) 14 15 234 126 -45 130 16 stk ( four elements ) 17 over 18 stk ( five elements ) 19 20 drop drop drop drop drop ( pop them all off ) 21 22 stk ( should be empty ) 23 cr ( new line ) 24 25 HALT 26 27 (----------------------------------------------------------) 28 29 ( EG102.ASM - mystery code ) 30 31 VARIABLE x VARIABLE y 32 33 x ? y ? 34 35 OVER OVER > IF SWAP ENDIF DROP . 36 37 HALT 38 39 (----------------------------------------------------------) 40 41 ( EG103.ASM - simple test of IF - ELSE - ENDIF ) 42 43 VARIABLE x 44 CONSTANT age 63 45 46 "Guess my age! " 47 48 x ? x @ age == 49 50 IF "correct" ELSE "incorrect" ENDIF 51 52 HALT 53 54 (----------------------------------------------------------) 55 56 ( EG104.ASM - boolean check a sequence of characters for being digits ) 57 58 VARIABLE ch 59 60 repeat 61 ch ?c 62 ch @ 63 dup '0' < 64 if 65 drop false 66 else 67 '9' > if false else true endif 68 endif 69 .b cr 70 ch @ '.' == 71 until 72 73 HALT 74 75 (----------------------------------------------------------) 76 77 ( EG105.ASM - new word 0== ) 78 79 VARIABLE x 80 81 repeat 82 x ? ( read x ) 83 x @ 0== 84 if "zero" else "non-zero" endif 85 x @ 0== 86 until 87 88 HALT 89 90 (----------------------------------------------------------) 91 92 ( EG106.ASM - bad constructs - can you detect the errors? ) 93 94 repeat 95 "in loop" 96 endif 97 repeat 98 "in second loop" 99 true 100 until 101 102 HALT 103 104 (----------------------------------------------------------) 105 106 ( EG107.ASM - simple colon definition ) 107 108 VARIABLE x 109 110 : =0 0 == ; ( test for zero ) 111 112 : @. @ . ; ( dereference and print ) 113 114 repeat 115 "\nPlease supply a number " 116 x ? ( read x ) 117 x dup @ =0 118 if @. " is zero " else @. " is non-zero " endif 119 x @ =0 120 until 121 122 HALT 123 124 (----------------------------------------------------------) 125 126 ( EG108.ASM - colon definitions ) 127 128 : <0 0 < ; ( test negative ) 129 130 : @=0 @ 0 == ; ( deref and test zero ) 131 132 : abs ( one way of doing it! ) 133 dup 134 <0 135 if negate endif 136 ; 137 138 VARIABLE x 139 140 repeat ( repeat ) 141 x ? ( read(x) ) 142 x @ abs . ( write(abs(x)) ) 143 cr 144 x @=0 ( until (x == 0) ) 145 until 146 147 HALT 148 149 (----------------------------------------------------------) 150 151 ( EG109.ASM - colon definitions - an upper case conversion ) 152 153 : toUpper ( if ('a' <= tos <= 'z') tos -= 32 ) 154 dup 'a' >= 155 if dup 'z' <= 156 if 32 - endif 157 endif 158 ; 159 160 VARIABLE ch 161 162 repeat ( repeat ) 163 ch ?c ( read(ch); ) 164 ch @ toUpper .c ( write(toUpper(ch)); ) 165 166 ch @ '.' == ( until (ch == '.') ; ) 167 until 168 169 HALT 170 171 (----------------------------------------------------------) 172 173 ( ED110.ASM - colon definitions and showing reverse polish expression evaluation ) 174 175 : PEEK DUP . DUP .c ; 176 177 65 PEEK 72 PEEK 3 * + . ( should print 281 ) 178 179 HALT 180 181 (----------------------------------------------------------) 182 183 ( EG111.ASM - colon definitions - count number of positive and negative values ) 184 185 VARIABLE x 186 VARIABLE pos 187 VARIABLE neg 188 189 : EVALUATE @ 0 >= IF "positive" pos ++ ELSE "negative" neg ++ ENDIF cr ; 190 191 : read(x) "\nSupply next number " x ? ; 192 193 : =0 0 ! ; 194 195 : display @ . ; 196 197 : zero? @ 0 == ; 198 199 pos =0 200 neg =0 201 repeat 202 read(x) x dup evaluate 203 zero? 204 until 205 pos display " non-negative numbers" cr 206 neg display " negative numbers" cr 207 208 HALT 209 210 (----------------------------------------------------------) 211 1 File: EG101.pvm 2 3 ASSEM 4 BEGIN 5 { 0 } DSP 0 6 { 2 } LDC 1 7 { 4 } LDC 2 8 { 6 } SWAP 9 { 7 } PRNI 10 { 8 } PRNI 11 { 9 } PRNL 12 { 10 } STK 13 { 11 } LDC 4 14 { 13 } LDC 5 15 { 15 } DROP 16 { 16 } PRNI 17 { 17 } PRNL 18 { 18 } STK 19 { 19 } LDC 234 20 { 21 } LDC 126 21 { 23 } LDC -45 22 { 25 } LDC 130 23 { 27 } STK 24 { 28 } OVER 25 { 29 } STK 26 { 30 } DROP 27 { 31 } DROP 28 { 32 } DROP 29 { 33 } DROP 30 { 34 } DROP 31 { 35 } STK 32 { 36 } PRNL 33 { 37 } HALT 34 END. 35 36 ------------------------------ 37 38 File: EG102.pvm 39 40 ASSEM 41 BEGIN 42 { 0 } DSP 2 43 { 2 } LDA 0 44 { 4 } INPI 45 { 5 } LDA 1 46 { 7 } INPI 47 { 8 } OVER 48 { 9 } OVER 49 { 10 } CGT 50 { 11 } BZE 14 51 { 13 } SWAP 52 { 14 } DROP 53 { 15 } PRNI 54 { 16 } HALT 55 END. 56 57 ------------------------------ 58 59 File: EG103.pvm 60 61 ASSEM 62 BEGIN 63 { 0 } DSP 1 64 { 2 } PRNS "Guess my age! " 65 { 4 } LDA 0 66 { 6 } INPI 67 { 7 } LDA 0 68 { 9 } LDV 69 { 10 } LDC 63 70 { 12 } CEQ 71 { 13 } BZE 19 72 { 15 } PRNS "correct" 73 { 17 } BRN 21 74 { 19 } PRNS "incorrect" 75 { 21 } HALT 76 END. 77 78 ------------------------------ 79 80 File: EG104.pvm 81 82 ASSEM 83 BEGIN 84 { 0 } DSP 1 85 { 2 } LDA 0 86 { 4 } INPC 87 { 5 } LDA 0 88 { 7 } LDV 89 { 8 } DUP 90 { 9 } LDC 48 91 { 11 } CLT 92 { 12 } BZE 19 93 { 14 } DROP 94 { 15 } LDC 0 95 { 17 } BRN 30 96 { 19 } LDC 57 97 { 21 } CGT 98 { 22 } BZE 28 99 { 24 } LDC 0 100 { 26 } BRN 30 101 { 28 } LDC 1 102 { 30 } PRNB 103 { 31 } PRNL 104 { 32 } LDA 0 105 { 34 } LDV 106 { 35 } LDC 46 107 { 37 } CEQ 108 { 38 } BZE 2 109 { 40 } HALT 110 END. 111 112 ------------------------------ 113 114 File: EG105.pvm 115 116 ASSEM 117 BEGIN 118 { 0 } DSP 1 119 { 2 } LDA 0 120 { 4 } INPI 121 { 5 } LDA 0 122 { 7 } LDV 123 { 8 } LDC 0 124 { 10 } CEQ 125 { 11 } BZE 17 126 { 13 } PRNS "zero" 127 { 15 } BRN 19 128 { 17 } PRNS "non-zero" 129 { 19 } LDA 0 130 { 21 } LDV 131 { 22 } LDC 0 132 { 24 } CEQ 133 { 25 } BZE 2 134 { 27 } HALT 135 END. 136 137 ------------------------------ 138 139 File: EG106.pvm 140 141 ASSEM 142 BEGIN 143 { 0 } DSP 0 144 { 2 } PRNS "in loop" 145 { 4 } PRNS "in second loop" 146 { 6 } LDC 1 147 { 8 } BZE 4 148 { 10 } HALT 149 END. 150 151 ------------------------------ 152 153 File: EG107.pvm 154 155 ASSEM 156 BEGIN 157 { 0 } DSP 1 158 { 2 } PRNS "\nPlease supply a number " 159 { 4 } LDA 0 160 { 6 } INPI 161 { 7 } LDA 0 162 { 9 } DUP 163 { 10 } LDV 164 { 11 } LDC 0 165 { 13 } CEQ 166 { 14 } BZE 22 167 { 16 } LDV 168 { 17 } PRNI 169 { 18 } PRNS " is zero " 170 { 20 } BRN 26 171 { 22 } LDV 172 { 23 } PRNI 173 { 24 } PRNS " is non-zero " 174 { 26 } LDA 0 175 { 28 } LDV 176 { 29 } LDC 0 177 { 31 } CEQ 178 { 32 } BZE 2 179 { 34 } HALT 180 END. 181 182 ------------------------------ 183 184 File: EG108.pvm 185 186 ASSEM 187 BEGIN 188 { 0 } DSP 1 189 { 2 } LDA 0 190 { 4 } INPI 191 { 5 } LDA 0 192 { 7 } LDV 193 { 8 } DUP 194 { 9 } LDC 0 195 { 11 } CLT 196 { 12 } BZE 15 197 { 14 } NEG 198 { 15 } PRNI 199 { 16 } PRNL 200 { 17 } LDA 0 201 { 19 } LDV 202 { 20 } LDC 0 203 { 22 } CEQ 204 { 23 } BZE 2 205 { 25 } HALT 206 END. 207 208 ------------------------------ 209 210 File: EG109.pvm 211 212 ASSEM 213 BEGIN 214 { 0 } DSP 1 215 { 2 } LDA 0 216 { 4 } INPC 217 { 5 } LDA 0 218 { 7 } LDV 219 { 8 } DUP 220 { 9 } LDC 97 221 { 11 } CGE 222 { 12 } BZE 23 223 { 14 } DUP 224 { 15 } LDC 122 225 { 17 } CLE 226 { 18 } BZE 23 227 { 20 } LDC 32 228 { 22 } SUB 229 { 23 } PRNC 230 { 24 } LDA 0 231 { 26 } LDV 232 { 27 } LDC 46 233 { 29 } CEQ 234 { 30 } BZE 2 235 { 32 } HALT 236 END. 237 238 ------------------------------ 239 240 File: EG110.pvm 241 242 ASSEM 243 BEGIN 244 { 0 } DSP 0 245 { 2 } LDC 65 246 { 4 } DUP 247 { 5 } PRNI 248 { 6 } DUP 249 { 7 } PRNC 250 { 8 } LDC 72 251 { 10 } DUP 252 { 11 } PRNI 253 { 12 } DUP 254 { 13 } PRNC 255 { 14 } LDC 3 256 { 16 } MUL 257 { 17 } ADD 258 { 18 } PRNI 259 { 19 } HALT 260 END. 261 262 ------------------------------ 263 264 File: EG111.pvm 265 266 ASSEM 267 BEGIN 268 { 0 } DSP 3 269 { 2 } LDA 1 270 { 4 } LDC 0 271 { 6 } STO 272 { 7 } LDA 2 273 { 9 } LDC 0 274 { 11 } STO 275 { 12 } PRNS "\nSupply next number " 276 { 14 } LDA 0 277 { 16 } INPI 278 { 17 } LDA 0 279 { 19 } DUP 280 { 20 } LDV 281 { 21 } LDC 0 282 { 23 } CGE 283 { 24 } BZE 33 284 { 26 } PRNS "positive" 285 { 28 } LDA 1 286 { 30 } INC 287 { 31 } BRN 38 288 { 33 } PRNS "negative" 289 { 35 } LDA 2 290 { 37 } INC 291 { 38 } PRNL 292 { 39 } LDV 293 { 40 } LDC 0 294 { 42 } CEQ 295 { 43 } BZE 12 296 { 45 } LDA 1 297 { 47 } LDV 298 { 48 } PRNI 299 { 49 } PRNS " non-negative numbers" 300 { 51 } PRNL 301 { 52 } LDA 2 302 { 54 } LDV 303 { 55 } PRNI 304 { 56 } PRNS " negative numbers" 305 { 58 } PRNL 306 { 59 } HALT 307 END. 308 309 ------------------------------ 310