Язык программирования Форт



Приложение Д. Ответы к упражнениям - часть 23


IF ." Block overrun " ABORT THEN 2 * >R PATBLOCK 2+ BLOCK R@ + ! UPDATE PATBLOCK 1+ BLOCK R@ + ! UPDATE PATBLOCK BLOCK R> + ! UPDATE ; : SD ( - n ) DUP 1+ 2 * 1024 >

IF ." Block overrun" ABORT THEN 2 * >R CR R@ 2 / ." Patient number " CR R@ PATBLOCK BLOCK + @ ." Weight " CR R@ PATBLOCK 1+ BLOCK + @ ." Systolic pressure " CR R@ PATBLOCK 2 + BLOCK + @ ." Diastolic pressure " . CR;

Блок 110 [110 :0] ( Глава 10. Упражнения 5. 03 из 05 ) ( 4.) VARIABLE CNT : SUMBLOCK ( n -- d ) 0 CNT ! BLOCK 0 0 RОТ 512 0 DO DUP I 2 * + @ DUP IF 1 CNT +! ТНEN SWAP >R 0 D+ R>

LOOP DROP : ( 5. ) : AVE ( n1 - n2 ) SUMBLOCK CNT @ 0 D/ DROP ; ( 6. ) : AD ( n -- ) PATBLOCK BLOCK @ 2 * 2+ DUP 1+ 1024 >

IF ." Block overrun" ABORT ELSE PATBLOCK BLOCK DUP >R + ! 1 R> ! UPDATE THEN ;

Блок 111 [111 :0] ( Глава 10. Упражнения 5. 04 из 05 ) ( 7.) : DD ( n -- ) 2 * 2+ PATBLOCK BLOCK DUP >R OVER + DUP 2- ROT 1024 SWAP - CMOVE -1 R> +! UPDATE ; ( 8. ) : SB ( n - d ) BLOCK DUP >R 0 0 ROT R> @ 0 DO DUP I 2 * + 2+ @ SWAP >R 0 D+ R> LOOP DROP ; : AV ( n1 -- n2) DUP SB ROT BLOCK @ 0 D/ DROP ; ( 9.) : SBS ( n -- d ) BLOCK DUP >R 0 0 ROT R> @ 0 DO DUP I 2 * + 6 + @ SWAP >R 0 D+ R> LOOP DROP ; : AVS ( n1 -- n2 ) DUP SBS ROT BLOCK @ 0 D/ DROP ;

Блок 112 [112 :0] ( Глава 10. Упражнения 5. 05 из 05 ) ( 9 продолж. ) : ADS ( n -- ) PATBLOCK BLOCK @ 2 * 6 + DUP 1024 2/ >

IF ." Block overrun" ABORT ELSE PATBLOCK BLOCK DUP >R + ! 1 R@ +! PATBLOCK SBS R> 2+ 2! UPDATE THEN ; : DDS ( n -- ) 2 * 6 + PATBLOCK BLOCK DUP >R OVER + DUP 2- ROT 1024 SWAP - CMOVE -1 R> + PATBLOCK SBS PATBLOCK BLOCK 2+ 2! UPDATE ; ( 10. ) : CHKSUM ( n1 -- n2 ) BLOCK 0 1024 0 DO OVER I + @ + 2 +LOOP SWAP DROP ; : ?BLK= ( n1 n2 -- флаг ) CHKSUM SWAP CHKSUM = ;

Блок 113 [113 :0] ( Глава 10. Упражнения 6. 01 из 02 ) ( 1.) : BLOCKWORD ( n1 n2 n3 -- #addr ) BLK @ >R >IN @ >R ROT BLK ! SWAP >IN ! WORD DUP C@ PAD SWAP 1+ CMOVE PAD R> >IN ! R> BLK ! ; ( 2.) VARIABLE POSITION 0 POSITION ! : BWORD ( n1 n2 -- #addr ) BLK @ >R >IN @ >R SWAP BLK ! POSITION @ >IN ! WORD DUP C@ PAD SWAP 1+ CMOVE >IN @ POSITION ! R> >IN ! R> BLK I PAD ; ( 3. ) : BLOCKNUMBER ( n1 n2 - n3) BWORD NUMBER DROP ;




Содержание  Назад  Вперед