08.04.2013 Views

Your Commodore - Commodore Is Awesome

Your Commodore - Commodore Is Awesome

Your Commodore - Commodore Is Awesome

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Homework - answer I<br />

MACHINE CODE<br />

1000 *- $C000 1570 TA?<br />

1010 BUFFER 8 3 0 1580 JMP LOOP4 ; NEXT WORD<br />

1020 CHROUT - $FFD2 1590 NOTFOUND LDA #MESS4<br />

1040 PRINTMESS - $ABlE 1610 JSR PRINTMESS<br />

1050 PRINTNO - $BDCD 1620 LDA NcBUFFER<br />

1060 COUNT - 899 1630 LDY #.>BUFFER<br />

1070 1640 JSR PRINTMESS<br />

1080 1650 RTS<br />

1090 LDY #0 ; INITIALISE BUFFER 1 6 6 0 FOUND LDA #MESS1<br />

1110 LOOP5 STA BUFFER,? 1680 JSR PRINTMESS<br />

1120 INY 1690 LDA 4BUFFER<br />

1140 BNE LOOP5 1710 JSR PRINTMESS<br />

1150 LDA 4147 ; PRINT PROMPT 1 7 2 0 LDA 4MESS3<br />

1240 BEQ LOOP2 1810 JSR PRINTMESS<br />

1250 STA BUFFER,? 1820 RTS<br />

1260 IN? 1830<br />

1270 JMP LOOPI 1840<br />

1280 LOOP2 CPY #4 ; IF WORD LESS THAN 1 8 5 0 TABLE .ASCI "TAKELOOKSINGEAT BITEKILL"<br />

1290 BCS LOOP& ; FOUR CHARS THEN PAD 1 8 6 0 .ASCI "THROLIGHORINCLIMSWIMFICHDROP"<br />

1300 LDA #32 ; IT WITH SPACES 1 8 7 0 TABLEN .BYTE 13<br />

1310 STA BUFFER,? 1880 MESS1 .ASCI "THE WORD "<br />

1320 IN? 1890 .BYTE 0<br />

1330 JMP LOOP2 1900 MESS2 .ASCI " IS NUMBER "<br />

1340 LOOP6 LDA #0 ; TERMINATE BUFFER WITH 1 9 1 0 .BYTE 0<br />

1350 STA BUFFER,Y ; ZERO 1 9 2 0 MESS3 .ASCI " IN MY WORD L I S T "<br />

1360 LDA #13 ; CARRIAGE RETURN 1 9 3 0 .BYTE 0<br />

1370 JSR CHROUT 1940 MESS4 .ASCI "I DON'T RECOGNISE "<br />

1380 1950 .BYTE 0<br />

1390<br />

1400 LDY *0 ; INITIALISE WORD COUNT<br />

1410 STY COUNT<br />

1420 LOOP4 LDX #0 ; SEARcH WORD TABLE<br />

1430 LOOP3 LDA BUFFER,X<br />

1440 CMP TABLE,?<br />

1450 BNE NOMATCH ; DOESN'T MATCH<br />

1460 INX ; IT MATCHED<br />

1470 IN? ; TRY NEXT CHARACTER<br />

1480 CPX 04<br />

1490 BNE L0OP3<br />

1500 JMP FOUND ; FOUND IT!<br />

1510 NOMATCH INC COUNT ; INCREMENT WORD COUNT<br />

1520 LDA COUNT<br />

1530 CMP TABLEN z ANY MORE WORDS TO CHECKPR1NT<br />

1540 BEQ NOTFOUND ;NO<br />

1550 ASL A ; BUMP COUNTER BY 4 TIMES<br />

1560 ASL A ; WORD NUMBER •<br />

3) If two words are found, the first is a<br />

verb and the second a noun e.g. TAKE<br />

SWORD, EAT SK AK E.<br />

Extract the verb and move it to a<br />

buffer starting at VERB and put it's<br />

length into VERBLEN.<br />

Similarly move the noun to a buffer<br />

starting at NOUN and its length into<br />

NOUN LEN.<br />

Consider this simple method of<br />

text compression. If you use just 32<br />

characters, you only need live bits to<br />

save each character. This being the<br />

case, you can save three characters in<br />

two bytes giving 33% saving in RAM.<br />

Consider this example:<br />

Character I — %000IIIII<br />

Character 2 — %00010101<br />

Character 3 — %%0001 lol l<br />

'I his compresses to:<br />

Byte I I 111101 and Byte 2:<br />

%0I110110<br />

As you can see, character I now<br />

YOUR COMMODORE november 1986:88<br />

occupies the top five bits of byte<br />

Character two occupies the bottom<br />

three bits of byte I and the top two bits<br />

of byte 2. Character three occupies bits<br />

I to bit 5 inclusive of byte 2. Bit 0 to<br />

byte 2 is set to zero.<br />

<strong>Your</strong> task is to:<br />

I) Develop an algorithm which<br />

performs the compression.<br />

2) Write a routine to do this job using<br />

so far as possible logical shifts and rolls<br />

and boolean instructions such as OR<br />

and AND.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!