📄 sub.med
字号:
1286 ;V3.04 ld (hl+OFF_S),0 ;V1.28 ;If all 0, then clear '-' sign V1.36
1287 wk_round_99:
1288 ret
1289 ;work reg. right shift with rounding data.......
1290 wk_rnd_10:
1291 ld b,(hl+OFF_LSD) ;keep LSD before right shift
1292 call stg_sfr47 ;work reg. right shift by nibble
1293 dec (hl+OFF_DP) ;DP-1
1294 ld a,(hl+OFF_DP) ;
1295 cmp a,(DP_POS) ;compare work register DP <> DP selector value
1296 j gt,wk_rnd_10 ;greater than DP selector -> contine right shift
1297 ;work reg. DP = DP selector......
1298 and b,0x0f ;check previouse LSD
1299 j z,wk_round_9 ; if previouse LSD is ? -> no round up
1301 +1 ld wa,SW_RNDUP
1302 +1 test (SW_RNDUP>>4).a ;bit -reverse-> jump status
1303 +1 j f,wk_rnd_up ;if jump status is 0 -> branch
1305 +1 ld wa,SW_RND54
1306 +1 test (SW_RND54>>4).a ;bit -reverse-> jump status
1307 +1 j t,wk_round_9 ;if jump status is 1 -> branch
1308 ;5/4...........
1309 cmp b,0x05
1310 j lt,wk_round_9 ; -> no round up
1311 ;round up......
1312 wk_rnd_up:
1313 ld c,OFF_LSD
1314 ld b,0y00000001 ;for set CF=1
1315 ;work reg. +1........
1316 wk_rnd_up0:
1317 ld a,(hl+c)
1318 ld CF,b.0 ;set CF
1319 addc a,0
1320 daa a ;decimal adjust for addition
1321 ld b.0,CF ;save CF to reg.b
1322 ld (hl+c),a
1323 dec c
1324 cmp c,OFF_MSD
1325 j ge,wk_rnd_up0
1326 j wk_round_9
1327
1328 ;==============================================================================
1329 ; work register update
1330 ;==============================================================================
1331 ; work reg <- work reg + W2
1332 ; input: hl <- work reg. address(keep hl content)
1333 ; output: work reg.
1334 ; *note: DP location is adjusted by follow DP selector value(DP_POS)
1335 ;
1336 wk_update:
1337 push hl
1338 ld ix,hl
1339 call move_to_w1 ;W1 <- work reg.
1341 +1 ld wa,F_MIN_TRA
1342 +1 test (F_MIN_TRA>>4).a ;bit -reverse-> jump status
1343 +1 j t,wk_update2 ;if jump status is 1 -> branch
1344 xor (W2_S),0x01 ;W2 sign change
1345 call calc_add ;W1 <- W1+W2
1346 xor (W2_S),0x01 ;W2 sign change
1347 j wk_update4
1348 wk_update2:
1349 call calc_add ;W1 <- W1+W2
1350 wk_update4:
1351 ld hl,W1 ;V1.33
1352 call _zerock ;V1.33 ;zero check working register(hl)
1353 j nz,wk_update5 ;V1.33
1354 ld (hl+OFF_S),0 ;V1.33 ;If all 0, then clear '-' sign
1355 wk_update5:
1357 +1 ld wa,F_CALER
1358 +1 test (F_CALER>>4).a ;bit -reverse-> jump status
1359 +1 j f,wk_update9 ;if jump status is 0 -> branch
1360 ld hl,W1
1361 call dp_adjust ;adjustment DP location for accumulated answer
1362 pop hl ;recover hl
1363 ld iy,hl ;work reg. address set to iy
1364 ld ix,W1
1365 call move_9byte ;work reg. <- W1
1366 ret
1367 wk_update9:
1368 pop hl ;recover hl
1369 ret
1370
1371 ;==============================================================================
1372 ; item counter update
1373 ;==============================================================================
1374 ; item counter <- item counter + 1
1375 ; input: hl <- work reg. address(keep hl content)
1376 ;
1377 ic_update:
1379 +1 ld wa,SW_ICPM
1380 +1 test (SW_ICPM>>4).a ;bit -reverse-> jump status
1381 +1 j t,ic_update0 ;if jump status is 1 -> branch
1383 +1 ld wa,F_MIN_TRA
1384 +1 test (F_MIN_TRA>>4).a ;bit -reverse-> jump status
1385 +1 j t,ic_update0 ;if jump status is 1 -> branch
1386 ;V2.03 @BBS (M_V1297,ic_update_y) ;V1.29
1387 ld a,(hl) ;V1.29
1388 and a,0x0f ;V1.29
1389 or a,(hl+1) ;V1.29
1390 j ne,ic_update_y1 ;V1.29
1391 ldw (hl),0x9909 ;V1.29
1392 jp ic_update_end ;V1.29
1393 ic_update_y: ;V1.17
1394 ld a,(hl) ;V1.26
1395 and a,0x10 ;V1.26
1396 j ne,ic_update01 ;V1.26
1397 ic_update_y1:
1398 set cf ;V1.17
1399 ld a,(hl+1) ;V1.17
1400 sub a,1 ;V1.17
1401 das a ;V1.17
1402 ld (hl+1),a ;V1.17
1403 ld a,(hl) ;V1.17
1404 and a,0x0f
1405 subb a,0 ;V1.17
1406 das a
1407 ld w,(hl)
1408 and w,0x10
1409 and a,0x1f
1410 or a,w
1411 ld (hl),a ;V1.17
1412 j cs,ic_update_y2
1413 ;--------------------------check item is "0"?
1414 ld w,(hl+1)
1415 ld a,(hl)
1416 and a,0x0f
1417 or a,w
1418 j ne,ic_update_end
1419 ld (hl),a
1420 jp ic_update_end
1421 ic_update_y2:
1422 ;V1.29 @BBC (M_V1297,ic_update_end) ;V1.26
1423 ld a,(hl) ;V1.26
1424 and a,0x10 ;V1.26
1425 j eq,ic_update_end ;V1.26
1426 push bc
1427 ld c,(hl+1)
1428 ld a,0
1429 set cf
1430 sub a,c
1431 das a
1432 ld (hl+1),a
1433 ld a,0
1434 ld c,(hl)
1435 and c,0x0f
1436 subb a,c
1437 das a
1438 and a,0x0f
1439 ld c,(hl)
1440 and c,0x10
1441 xor a,c
1442 ld (hl),a
1443 pop bc
1444 jp ic_update_end ;V1.17
1445 ic_update0: ;V1.17
1446 ;V1.29 @BBC (M_V1297,ic_update01) ;V1.26
1447 ld a,(hl) ;V1.26
1448 and a,0x10 ;V1.26
1449 j ne,ic_update_y1 ;V1.26
1450 ic_update01:
1451 ld a,(hl+1)
1452 add a,1
1453 daa a
1454 ld (hl+1),a
1455 ld a,(hl)
1456 addc a,0
1457 daa a
1458 and a,0x0f
1459 ld w,(hl) ;V1.26
1460 and w,0x10 ;V1.26
1461 or a,w ;V1.26
1462 ld (hl),a
1463 ;--------------------------check item is "0"?
1464 ld w,(hl+1)
1465 ld a,(hl)
1466 and a,0x0f
1467 or a,w
1468 j ne,ic_update_end
1469 ld (hl),a
1470 ic_update_end:
1471 ret
1472
1473 ;==============================================================================
1474 ; Basic calculation routines (Addtion/Subtruction)
1475 ;==============================================================================
1476 ;
1477 ; W1 <- W1 + or - W2
1478 ; note: W2 value is kept as before calculation
1479 ; note: use W3
1480 ;
1481 calc_add:
1483 +1 ld wa,F_CALER
1484 +1 test (F_CALER>>4).a ;bit -reverse-> jump status
1485 +1 j t,cadd_00 ;if jump status is 1 -> branch
1486 ret
1487 cadd_00:
1488 call w2_to_w3 ;for keep W2 contents
1489 call adjust_dpw12 ;adjust DP position for W1 and W2
1490 cadd_01:
1491 ld a,(W1_S)
1492 j nz,cadd_15 ;W1 is 'Minus'? yes->
1493 ld a,(W2_S)
1494 j nz,cadd_20 ;W2 is 'Minus'? yes->
1495
1496 ;W1 and W2 both 'Plus' or both 'Minus'...........
1497 cadd_09:
1498 call add_00 ;WORK_01<-WORK_01+WORK_02
1499 j cc,csub_99 ;no carry? yes-> exit
1500 ;Carry occur.............
1501 ld hl,W1
1502 call stg_sfr47 ;W1 right shift
1503 set (W1_MSD).4 ;set carry to MSD
1504 dec (W1_DP) ;W1_DP decrement
1505 j t,error_calc ;if DP is 'Minus'? yes-> over flow error
1506 j csub_99 ; -> exit
1507
1508 cadd_15:
1509 ld a,(W2_S)
1510 j nz,cadd_09 ;W1 is 'Minus' and W2 is 'Minus'? yes->
1511 cadd_20:
1512 ;W1 is 'Plus'and W2 is 'Minus' ..................
1513 ;or W1 is 'Minus' and W2 is 'Plus'...............
1514 call sub_00 ;WORK01<-WORK_01-WORK_02
1515 j cc,csub_99 ;no borrow? yes-> exit
1516 ;Borrow occur -> (00 --- 00) - calculated answer........
1517 ld c,0
1518 clr cf ;clear borrow flag
1519 push psw ;borrow flag save
1520 ld ix,W1_LSD
1521 csub_03:
1522 pop psw ;borrow flag recover
1523 ld a,0
1524 subb a,(ix)
1525 das a ;decimal adjust for subtruction
1526 ld (ix),a ;(W1) <- (00......00)-(W1)
1527 push psw ;borrow flag save
1528 dec ix
1529 inc c
1530 cmp c,LENG_WK
1531 j lt,csub_03 ;if c is lower than length of work area? yes->loop
1532 pop psw ;borrow flag recover
1533 xor (W1_S),0x01 ;sign invert
1534 csub_99:
1535 call adjust_12 ;adjust 14digit result -> 12 digits/or 10 digit
1536 j m,error_calc ;W1_DP is minus? yes-> error
1537 call zsup_under_dp
1538 call neg_check ;if W1 contents is -0, then convert to --> 0
1539 call w3_to_w2 ;restore w2
1540 ret
1541
1542 ;==============================================================================
1543 ; Basic calculation routines (Multiplication)
1544 ;==============================================================================
1545 calc_mult:
1547 +1 ld wa,F_CALER
1548 +1 test (F_CALER>>4).a ;bit -reverse-> jump status
1549 +1 j t,cmul_00 ;if jump status is 1 -> branch
1550 ret
1551 cmul_00:
1552 call w1_to_w3
1553 call w1_clear
1554
1555 ld c,(W2_DP) ;DP culculation W1_DP <- W3_DP(W1_DP) + W2_DP
1556 add c,(W3_DP) ;reg.c is use for keep DP value (BBC,CLB macro use wa register)
1558 +1 ld wa,F_PERCAL
1559 +1 test (F_PERCAL>>4).a ;bit -reverse-> jump status
1560 +1 j t,cmul_07 ;if jump status is 1 -> branch
1561 add c,2 ;yes -> add more 2
1563 +1 ld wa,F_PERCAL
1564 +1 clr (F_PERCAL>>4).a
1565 cmul_07:
1566 ld (W1_DP),c ;store calculated dp
1567 ld (W3_DP),0 ;clear loop counter
1568 cmul_08:
1569 ld a,(W3_LSD)
1570 and a,0x0f
1571 j nz,cmul_85
1572 inc (W3_DP) ;increment loop cnt
1573
1574 ;4bit Right shift W1_S to W1_LSD(8bytes) -> W3_MSD to W3_LSD(7bytes)..................
1575 cmul_09:
1576 ld hl,W1
1577 ld c,OFF_S
1578 ld a,0 ;shift W1_S to W1_LSD(16digits)
1579 cmul_10:
1580 rord a,(hl+c)
1581 inc c
1582 cmp c,OFF_DP
1583 j lt,cmul_10 ;if c is lower than offset of dp pointer? yes->loop
1584 ld hl,W3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -