Ch 14 BCD ¼Æ(2)¡GBCD ¤§¿é¤J»P­¼ªk

«D»E¶° BCD ­¼ªk­ì©lµ{¦¡

¦b³o¤@³¹ùؤp¤ì°¸±N©µÄò¤W¤@³¹ªºÆ[©À¡A¹ê§@¤@­Ó¥ô·N¦ì¼Æ¤§­¼ªkµ{¦¡¡C¨Ï¥ÎªÌ±N¥i¥H¿é¤J³Q­¼¼Æ»P­¼¼Æ¡A¦Óµ{¦¡±N¦Û°Êºâ¥X­¼¿n¨ÃÅã¥Ü©ó¿Ã¥ú¹õ¤W¡C³o­Óµ{¦¡¦b¦ì§}ªº­pºâ¤W¬Û·í½ÆÂø·Ð¤H¡A­n¦³¤@¨Ç­@¤ß¡C

­ì©lµ{¦¡¦p¤U¡G

digit           equ     20      ;01 ¦ì¼Æ
cr              equ     0dh     ;02 Âk¦ì¦r¤¸
lf              equ     0ah     ;03 ´«¦æ¦r¤¸
escape          equ     1bh     ;04 Esc Áä
backspace       equ     08h     ;05 ­Ë°hÁä
;***************************************
code    segment
        assume  cs:code,ds:code
        org     100h
        extrn   ubcd_print:near,ubcd_add:near
;---------------------------------------
start:  jmp     begin
;¸ê®Æ°Ï
mes1    db      cr,lf,'¿é¤J³Q­¼¼Æ¡G$'
mes2    db      cr,lf,'¿é¤J­¼¼Æ¡G$'
v1      db      digit dup (0),cr        ;16 ³Q­¼¼Æ
v2      db      digit dup (0),cr        ;17 ­¼¼Æ
product db      digit*2 dup (0),cr      ;18 ­¼¿n
len_v1  db      ?                       ;19 ³Q­¼¼Æ¦ì¼Æ
len_v2  db      ?                       ;20 ­¼¼Æ¦ì¼Æ
last_ad dw      ?                       ;21 ¦¹µ{¦¡³Ì°ª¦ì§}¦A¥[20H

;¨D¦¹µ{¦¡ªº³Ì°ª¦ì§}¦A¥[20H
begin:  mov     ax,offset end_prog      ;24 ¨ú±o print_cr_lf °Æµ{¦¡³Ì«á¦ì§}
        add     ax,3bh+39h+20h
        and     ax,0fff0h
        mov     last_ad,ax              ;27 ¦s¤J last_ad ÅܼÆ

        mov     dx,offset mes1  ;29 ¿é¤J³Q­¼¼Æ
        mov     ah,9
        int     21h
        mov     cx,digit
        mov     si,offset v1
        call    ubcd_input
        mov     len_v1,ch       ;35 ±N¿é¤J¦ì¼Æ¦s©ó len_v1

        mov     dx,offset mes2  ;37 ¿é¤J­¼¼Æ
        mov     ah,9
        int     21h
        mov     cx,digit
        mov     si,offset v2
        call    ubcd_input
        mov     len_v2,ch       ;43 ±N¿é¤J¦ì¼Æ¦s©ó len_v2

        mov     ax,offset v1    ;45 ­pºâ­¼¿n
        mov     bx,offset v2
        mov     dx,offset product
        mov     ch,len_v1
        mov     cl,len_v2
        call    ubcd_mul        ;50
        call    print_cr_lf     ;51 ´«¦æ

;¦L¥X¡y³Q­¼¼Æ¡z¡y*¡z¡y­¼¼Æ¡z¡y=¡z¦r¼Ë
        mov     si,offset v1    ;54
        mov     cx,digit
        call    ubcd_print
        mov     dl,'*'
        call    print_char
        mov     si,offset v2
        mov     cl,len_v2
        sub     ch,ch
        call    ubcd_print
        mov     dl,'='
        call    print_char      ;64

;­pºâ­¼¿n¦ì¼Æ=¡y³Q­¼¼Æ¦ì¼Æ¡z¥[¡y­¼¼Æ¦ì¼Æ¡z
        mov     cl,len_v1       ;67
        add     cl,len_v2
;¦L¥X¡y­¼¿n¡z
        mov     si,offset product
        call    ubcd_print      ;71

        mov     ax,4c00h
        int     21h             ;74 µ²§ô
;---------------------------------------
;¥Øªº¡G¥ÑÁä½L¿é¤J¤Q¶i¦ì¼Æ¨ÃÂà´«¦¨³Ì¤j¦ì¼Æ©ó°ª¦ì§}ªº«D»E¶°BCD¼Æ
;¿é¤J¡GSI¡G«D»E¶°BCD¤§³Ì§C¦ì§}
;      CX¡G«D»E¶°BCD¤§³Ì¤j¦ì¼Æ¡A¦ýCH¥²¬°0
;¿é¥X¡GCL¡G«D»E¶°BCD¤§³Ì¤j¦ì¼Æ¡A»P¿é¤J­È¤§CL¬Û¦P
;      CH¡G¹ê»Ú¿é¤J¦ì¼Æ
;      AL¡G0ªí¥Ü¿é¤J¥¿±`¡A1BHªí¥Ü«ö¤UEscÁä
;      AH¡NDX¡G·|³Q¯}Ãa¡A¨ä¾l¤£ÅÜ
ubcd_input      proc    near    ;83
        push    bx
        push    di

;©ó¼È¦s°Ï(temp_ubcd_rev)¤¤¿é¤J«D»E¶°BCD¼Æ(³Ì¤j¦ì¼Æ©ó§C¦ì§})
        sub     bx,bx           ;88 BX³]¬°¹s¡Aº¸«áBX¬°temp_ubcd_rev¤§«ü¼Ð
ipn0:   mov     ah,0
        int     16h             ;90 ¿é¤Jªü©Ô§B¼Æ¦r¤§ ASCII
        cmp     al,escape
        je      ipn4
        cmp     al,cr
        je      ipn1
        cmp     al,backspace
        je      ipn5
        cmp     al,'0'          ;97 Àˬd¬O§_¬°ªü©Ô§B¼Æ¦r
        jb      ipn0
        cmp     al,'9'
        ja      ipn0
        mov     dl,al
        call    print_char
        sub     al,'0'          ;103 ¨Ï¤§Åܦ¨BCDªº¤@¦ì¼Æ
        mov     temp_ubcd_rev[bx],al
        inc     bx              ;105 «ü¼Ð¥[¤@
        cmp     bx,cx           ;106 CX¬°³Ì¤j¦ì¼Æ
        jne     ipn0

;±Ntemp_ubcd_rev¤§¼Æ¦rÂà´«¦¨¤j¦ì¼Æ¦b°ª¦ì¤¸ªºBCD¼Æ
ipn1:   or      bx,bx           ;110 Àˬd¬O§_¥u¿é¤JEnterÁä
        je      ipn6            ;111 ¬O«h¸õ¦Üipn6¼Ð°O³B
        sub     di,di           ;112 DI¥Ñ¼È¦s°Ïªº§C¦ì§}³B¶}©l
        mov     ch,bl           ;113 ³]©w¹ê»Ú¿é¤J¦ì¼Æ
ipn2:   mov     al,temp_ubcd_rev[di]    ;114 ¨ú±o¼È¦s°ÏBCD¼Æ¦r
        mov     [si+bx-1],al    ;115 ¦s¤J¤÷µ{¦¡«ü©w¦ì§}
        inc     di
        dec     bx
        jnz     ipn2
ipn3:   sub     al,al           ;119 ¥¿±`ªð¦^¤÷µ{¦¡
ipn4:   pop     di
        pop     bx
        ret

;«ö¤UBackspace(­Ë°hÁä)
ipn5:   or      bx,bx           ;125 Àˬd¬O§_¤w¸g¨ì³Ì«e­±
        je      ipn0
        mov     dl,al           ;127 ´å¼Ð­Ë°h¤@®æ
        call    print_char
        mov     dl,' '          ;129 ®ø¥h¿Ã¹õ¤WªºÂ¸ê®Æ
        call    print_char
        mov     dl,backspace    ;131 ´å¼Ð­Ë°h¤@®æ
        call    print_char
        dec     bx              ;133 temp_ubcd_rev¤§«ü¼Ð´î¤@
        jmp     ipn0

;¥u¿é¤JEnterÁä¡A§Y¨Ï¥ÎªÌ¿é¤J¡y0¡z
ipn6:   mov     ch,1
        mov     byte ptr [si],0
        jmp     ipn3

print_char:
        mov     ah,2
        int     21h
        ret

;¼È®É¦s©ñ¿é¤JBCD¼Æ³B¡A¦¹¼Æ¦r¤j¦ì¼Æ¦b§C¦ì§}³B
temp_ubcd_rev   db      digit dup (0)   ;147
ubcd_input      endp
;---------------------------------------
;­pºâ¨â«D»E¶°BCD¼Æ¤§­¼¿n        ;150
;¿é¤J¡GAX¡G³Q­¼¼Æ¦ì§}
;      BX¡G­¼¼Æ¦ì§}
;      DX¡G­¼¿n¦ì§}
;      CH¡G³Q­¼¼Æ¦ì¼Æ
;      CL¡G­¼¼Æ¦ì¼Æ
;¿é¥X¡G©óDX©Ò«üªº¦ì§}¦C¥X­¼¿n
;      AX¡NBX¡NCX¡NDX¡NSI¡NDI§¡³Q¯}Ãa
ubcd_mul        proc    near
        mov     l_adr_v2,bx     ;159 ±N³Q­¼¼Æ¡N­¼¼Æ³Ì§C¦ì§}¤À§O¦s©ó
        mov     l_adr_v1,ax     ;160 l_adr_v1¡Nladr_v2
        sub     bx,bx           ;161 ­pºâ³Q­¼¼Æ³Ì¤j¦ì¼Æ©Ò¦b¦ì§}¡A¨Ã¦s©ó
        mov     bl,ch           ;162 h_adr_v1
        add     ax,bx
        mov     h_adr_v1,ax
        mov     bl,cl           ;165 ­pºâ­¼¼Æ³Ì¤j¦ì¼Æ©Ò¦b¦ì§}¡A¨Ã¦s©ó
        add     bx,l_adr_v2     ;166 h_adr_v2
        mov     h_adr_v2,bx
        add     cl,ch           ;168 ­pºâ­¼¿n¦ì¼Æ¡A¨Ã¦s©ó len_p
        sub     ch,ch
        mov     len_p,cx
        push    dx              ;171 «O¦s­¼¿n¦ì§}¡A«Ý²Ä¤G­Ó¤j°j°é¤~¨Ï¥Î(222¦æ)
        mov     bx,dx
m0:     mov     byte ptr [bx],ch;173 ²M°£­¼¿nªº©U§£¸ê®Æ
        inc     bx
        loop    m0
        
;²Ä¤@­Ó¤j°j°é¡A³B²z¨C¤@¦ì­¼¼Æ¥h­¼³Q­¼¼Æ
        mov     di,last_ad      ;178 DI«ü¦V¼È¦s°Ï(¦s©ñ¨C¤@¦ì­¼¼Æ¬Û­¼«áªºµ²ªG)
        mov     si,l_adr_v2     ;179 ¨C¦¸­pºâ­¼¼Æ¤@¦ì¼Æ­¼³Q­¼¼Æµ²ªG¤§°j°é¶}©l
m1:     sub     ax,ax           ;180 ²M°£AX¡NDH¨Ï©¹«áªºAAM¡NAAA«ü¥O¯à¥¿½T¹Bºâ
        mov     dh,al

        mov     cx,si           ;183 ¤p¦ì¼Æªº¶ñ¹s³¡¤À¡ACX¬°¶ñ¹sªº­Ó¼Æ
        sub     cx,l_adr_v2
        mov     bx,l_adr_v1     ;185 ­pºâ­¼¼Æ¨C¦ì¼Æ­¼³Q­¼¼Æ³¡¤À
        push    cx
        jcxz    m3
m2:     mov     [di],al
        inc     di
        loop    m2              ;190
		
m3:     mov     al,[bx]         ;192 BX«ü¦V³Q­¼¼Æ
        mul     byte ptr [si]
        aam
        add     al,dh           ;195 ¥[¤W«e¤@¦¸ªº¶i¦ì
        aaa
        mov     dh,ah           ;197 ¶i¦ì¦s©óDH
        mov     [di],al
        inc     bx
        inc     di
        cmp     bx,h_adr_v1
        jne     m3              ;202
		
        mov     [di],dh         ;204 ³B²z¶i¦ì³¡¤À
        inc     di              ;205

        pop     ax              ;207 ³B²z¤j¦ì¼Æ¶ñ¹s³¡¤À
        mov     cx,len_p        ;208 CX¬°¶ñ¹sªº­Ó¼Æ
        sub     bx,l_adr_v1
        sub     cx,ax
        sub     cx,bx
        dec     cx
        jcxz    m5
m4:     mov     byte ptr [di],0
        inc     di
        loop    m4              ;216

m5:     inc     si              ;218 «ü¦V­¼¼Æªº¤U¤@¦ì
        cmp     si,h_adr_v2     ;219 Àˬd­¼¼Æ¬O§_³£¤wºâ§¹
        jne     m1

;²Ä¤G­Ó¤j°j°é¡A³B²z¨C¤@¦ì­¼¼Æ­¼¿n¤§©M
        mov     cx,h_adr_v2
        sub     cx,l_adr_v2     ;224 CX¬°­¼¼Æ¦ì¼Æ¡A§Y­n¬Û¥[¦¸¼Æ
        pop     si              ;225 ¨ú¦^­¼¿n¦ì§}
        mov     bx,last_ad      ;226 BX¬°¼È¦s°Ï¦ì§}
m6:     push    cx
        mov     dx,si
        mov     ax,dx
        push    bx
        mov     cx,len_p
        mov     ch,cl
        call    ubcd_add        ;233 DX=DX+BX
        pop     bx
        pop     cx
        add     bx,len_p
        loop    m6              ;237
        ret
l_adr_v1        dw      ?       ;239 ³Q­¼¼Æ³Ì§C¦ì§}
l_adr_v2        dw      ?       ;240 ­¼¼Æ³Ì§C¦ì§}
h_adr_v1        dw      ?       ;241 ³Q­¼¼Æ³Ì°ª¦ì§}
h_adr_v2        dw      ?       ;242 ­¼¼Æ³Ì°ª¦ì§}
len_p           dw      ?       ;243 ­¼¿n¦ì¼Æ
ubcd_mul        endp            ;244
;---------------------------------------
print_cr_lf     proc    near
        mov     dl,cr
        call    print_char
        mov     dl,lf
        call    print_char
        ret
print_cr_lf     endp
;---------------------------------------
end_prog:                       ;254 µ{¦¡³Ì°ª¦ì§}
code    ends
;***************************************
        end     start

³o­Óµ{¦¡ªº¬yµ{«Ü²³æ¡A­«ÂI¦b¨â­Ó·sªº°Æµ{¦¡ ( ubcd_input »P ubcd_mul )¡AÁÙ¦³­pºâµ{¦¡µ²§ô¦ì§}¡C¦n§a¡A§Ú­Ì¥ý¥ý¨Ó¡y¸Ñ­å¡zubcd_input °Æµ{¦¡§a¡C

ubcd_input °Æµ{¦¡

³o­Ó°Æµ{¦¡¬O¥Î¨ÓÅý¨Ï¥ÎªÌ¥ÑÁä½L¿é¤J¤@­Ó¼Æ¦r¡A¨Ã¥BÂà´«¦¨«D»E¶°ªº BCD ¼Æ¡C¦p¦P«e­±©Ò¨¥¡A¤HÃþªº²ßºD¬O¥Ñ¤j¦ì¼Æ¶}©l¿é¤J ( ©Î®Ñ¼g )¡A¦A¨Ì¦¸»¼´î¡A¦ý¬O¹q¸£¤W¥ý¿é¤Jªº¦r«o©ñ¦b§C¦ì§}¡A©ó¬O¤H¥ý¿é¤Jªº¼Æ¦r«oÅܦ¨¦b§C¦ì§}¤F¡A³o·|²£¥Í¥Ù¬Þ¡C¬°¤F¸Ñ¨M¦¹¤@°ÝÃD¡A©ó¬O¤p¤ì°¸³]­p¤F¤@­Ó¼È¦s°Ï¡A¦W¬° temp_ubcd_rev ( rev ¬O reverse ¤§Â²¼g¡A§YÄA­Ë¤§·N )¡A·í¨Ï¥ÎªÌ¿é¤J¼Æ¦r®É¡A¨C¤@¦ì¼Æ³£«ö·Ó¥ý«á¶¶§Ç¨Ì¦¸¥Ñ§C¦ì§}±Æ¦V°ª¦ì§}¡A«Ý¨Ï¥ÎªÌ¿é¤J§¹²¦«á¦A¥Ñ²Ä 110 ¦æ¨ì²Ä 119 ¦æªºµ{¦¡³B²z¡A±N¼È¦s°Ï¤¤ÄA­Ëªº«D»E¶° BCD ¼ÆÅܦ¨¥¿±`ªº BCD ¼Æ¡C

¦b¾ã­Ó¹Lµ{¤¤¡ABX ¼È¦s¾¹©Ò§êºtªº¨¤¦â¦Ü¬°­«­n¡A¥¦¬O¥Nªí temp_ubcd_rev ªº«ü¼Ð¡C¤@¶}©l BX ¤§­È¬°¹s¡A¥Nªí¥¦«ü¨ì temp_ubcd_rev ªº³Ì§C¦ì§} (³Ì«e­±)¡A¦Ó«á¨C·í¨Ï¥ÎªÌ¥¿½T¦a¿é¤J¤@¦ì¼Æ (¥Ñµ{¦¡²Ä 97 ¦æ¨ì²Ä 102 ¦æÀˬd¨Ã¦L¦b¿Ã¹õ¤W)¡ABX ¤§­È´N¼W¥[¤@¡C¦p¤U¹Ï©Ò¥Ü¡G

°ò©³¬Û¹ï©w§}

°ò©³¬Û¹ï©w§}

·í¨Ï¥ÎªÌ¿é¤J¤@­Ó¼Æ¦r«á¡A´N±o±N³o­Ó¼Æ¦r¦s¤J temp_ubcd_rev ¼È¦s°Ï¤º¡A¦Ü©ó¬O¦s¤J¼È¦s°Ïªº¨º¤@­Ó¦ì§}«h¬O¥Ñ BX ¤§­È¨M©w¡Cµ{¦¡²Ä 104 ¦æ´N¬O°õ¦æ³o¥ó¨Æ¡C

mov     temp_ubcd_rev[bx],al

¤W¦¡µ{¦¡¬O¤@ºØ«e­±¨S´£¨ì¹Lªº©w§}¤è¦¡¡AºÙ°ò©³¬Û¹ï©w§}¡Ctemp_ubcd_rev[bx] ©Ò«üªº¦ì§}¡A¬O temp_ubcd_rev ©Ò¦b¦ì§}«áªº²Ä´X­Ó¦ì§}¡A¦Ü©ó¬O¤§«áªº¨º¤@­Ó¦ì§}­n¬Ý BX ªº¼Æ­È¡C¦pªG BX ¬°¹s¡A¸Ó¦ì§}´N¬O temp_ubcd_rev ³o­Ó¦ì§}¡A¦pªG BX ¬°¤@¡A¸Ó¦ì§}´N¬O temp_ubcd_rev ³o­Ó¦ì§}ªº¤U¤@­Ó¦ì§}(°ª¤@­Ó¦ì§})¡C¥Î DEBUG ¨ÓÆ[¹îµ{¦¡ 104 ¦æªº±¡§Î¡A·í ubcd_input °Æµ{¦¡­n§Ú¿é¤J®É¡A§Ú«ö¤U¡y9¡z³o­ÓÁä¡A¦b°õ¦æ

mov     temp_ubcd_rev[bx],al

³o¦æµ{¦¡¤§«e¡A¥ýÆ[¹î temp_ubcd_rev ¼È¦s°Ï¡A³o­Ó¼È¦s°Ï¦b¦ì§} 1C8E:0259 ¶}©lªº 20 ­Ó¦ì¤¸²Õ³B (¥i¥H¥Ñ MASM.EXE ²ÕĶ«á°ÆÀɦW¬° LST ªºÀÉ®×±oª¾)¡A¦ý§Ú¥uÆ[¹î«e´X­Ó¡C

-d 259 L7 [Enter]
1C8E:0250                             00 00 00 00 00 00 00

°õ¦æ«e³£¬O¹s¡C¦n¡A¬Ý¬Ý mov temp_ubcd_rev[bx],al ³o­Ó«ü¥O¡A³ºµMÅܦ¨¡yMOV [BX+0259],AL¡z¤F¡A¨Æ¹ê¤W¡A³o­Ó 0259 ´N¬O temp_ubcd_rev ªº©Ò¦b¦ì§}¡C

-r [Enter]
AX=0209  BX=0000  CX=0014  DX=0139  SP=FFF8  BP=0000  SI=011F  DI=0000
DS=1C8E  ES=1C8E  SS=1C8E  CS=1C8E  IP=0216   NV UP EI PL NZ NA PE NC
1C8E:0216 88875902      MOV     [BX+0259],AL                       DS:0259=00
-t [Enter]

AX=0209  BX=0000  CX=0014  DX=0139  SP=FFF8  BP=0000  SI=011F  DI=0000
DS=1C8E  ES=1C8E  SS=1C8E  CS=1C8E  IP=021A   NV UP EI PL NZ NA PE NC
1C8E:021A 43            INC     BX
-d 250 L7 [Enter]
1C8E:0250                             09 00 00 00 00 00 00   .......!........

¦]¬°¤@¶}©l¡ABX ¬°¹s¡A©Ò¥H BCD ¼Æ¡A9¡A¶ñ¦b 1C8E:0259 ³B¡C¨ä¹ê¤W­zµ{¦¡¤]¥i¥H§ï¼g¦¨¡G

mov     si,offset temp_ubcd_rev
add     bx,si
mov     [bx],al

°õ¦æµ²ªG¬O¤@¼Ëªº¡A¥u¬O¦h¥Î¤F¤@­Ó SI ¼È¦s¾¹¡Cubcd_input °Æµ{¦¡¤¤ÁÙ¦³³B²z¨Ï¥ÎªÌ«ö¤U Enter Áä¡NEsc Áä¥H¤Î¨ä¥L¡y¤£¦Xªk¡zªº«öÁä¡A¦ý³o¨Ç¨Ã¤£Ãø¡A¤p¤ì°¸´N¤£¦A»¡©ú¤F¡C

ubcd_mul °Æµ{¦¡

³o­Ó°Æµ{¦¡ªº­ì²z¡A»¡¬ï¤F¤]¤£­È´X¤å¿ú¡A¨ä¹ê´N¬O¤p¾Ç®É¦Ñ®v©Ò±Ðªºª½¦¡­¼ªk¡C¦^·Q¤@¤U¡A°²¦p­n¨D 98765*123¡A§A·|«ç»òºâ¡H§Ú·Q¤j³¡¤Àªº¤H·|±Ä¤U­±ªººâªk¡G

³Q­¼¼Æ         9 8 7 6 5
  ­¼¼Æ   ¢æ        1 2 3
--------------------------
             2 9 6 2 9 5
           1 9 7 5 3 0
           9 8 7 6 5
--------------------------
  ­¼¿n   1 2 1 4 8 0 9 5

¤p¤ì°¸©Ò¼gªºµ{¦¡¤]¬O§Q¥Î³o­Ó¤èªk¡A¥Ñ­¼¼Æªº­Ó¦ì¼Æ°_¡A­¼¤W³Q­¼¼Æ¡A¦A´«­¼¼Æªº¤Q¦ì¼Æ­¼¤W³Q­¼¼Æ¡Aª½¨ì­¼¼Æ©Ò¦³¦ì¼Æ³£­¼¤W³Q­¼¼Æ¥H«á¡A¦A¥þ³¡¬Û¥[°_¨Ó¡A´N¬O­¼¿n¤F¡C©Ò¥H¡A¾ã­Ó ubcd_mul °Æµ{¦¡ªº¬[ºc´NÅã²{¤F¡A¦³¨â­Ó¤j°j°é¡C²Ä¤@­Ó¤j°j°é³B²z­¼¼Æªº¨C¤@¦ì¼Æ­¼³Q­¼¼Æ¡A±o¨ì¤W¦¡¨â±ø½u¤§¶¡ªº¼Æ¡C²Ä¤G­Ó¤j°j°é³B²z¨C¤@¦ì¼Æ­¼³Q­¼¼Æ©Ò±oªº¼Æ¬Û¥[¡A¤]´N¬O§â¨â±ø½u¤§¶¡ªº­¼¿n¬Û¥[¡A´N±o¨ìµª®×¤F¡C

¦n¡A¦A¨Ó¬Ý¬Ý²Ä¤@­Ó¤j°j°é¤º¡A¨C¤@¦ì­¼¼Æ¥h­¼³Q­¼¼Æ·|µo¥Í¨º¨Ç¨Æ±¡¡C¤p¤ì°¸¥Î¯S®íÂoÃè·Ó¥X¤U¦¡¡G

³Q­¼¼Æ         9 8 7 6 5
  ­¼¼Æ   ¢æ        1 2 3
--------------------------
         0 0 2 9 6 2 9 5
         0 1 9 7 5 3 0 0
         0 9 8 7 6 5 0 0
--------------------------
  ­¼¿n   1 2 1 4 8 0 9 5

¥J²ÓÆ[¹î¤W¦¡­¼ªk¡A·í­¼¼Æªº¨C¤@¦ì¼Æ­¼³Q­¼¼Æ®É (¨Ò¦p­¼¼Æªº­Ó¦ì¼Æ 3 ­¼¥H 98765 ³oºØ±¡§Î)¡A¥i¤À¬°¥|­Ó¨BÆJ¡C²Ä¤@¨B¬O³Ì¥kÃ䪺¦Û°Ê¶ñ¹s (¾ï¦â³¡¤À)¡A¦Ü©ó¶ñ¦h¤Ö¦ì¹s¡A¬O¬Ý­¼¼Æªº¦ì¼Æ¦Ó©w¡A¦pªG­¼¼Æªº­Ó¦ì¼Æ­¼³Q­¼¼Æ¡A¨º¤£¶·¶ñ¹s¡F­¼¼Æªº¤Q¦ì¼Æ­¼³Q­¼¼Æ¡A­n¶ñ¤@­Ó¹s¡F­¼¼Æªº¦Ê¦ì¼Æ­¼³Q­¼¼Æ¡A­n¶ñ¨â­Ó¹s¡A¨Ì¦¹Ãþ±À¡C²Ä¤G¨B¬O¤¤¶¡ºñ¦â³¡¤À¬O¹ê»Ú¶i¦æ­¼ªk¹Bºâªº³¡¤À¡C²Ä¤T¨B¬O¶i¦ì³¡¤À (¥Õ¦â³¡¤À)¡C³Ì«á¤@¨B¬O¤j¦ì¼Æªº¶ñ¹s³¡¤À (³Ì¥ªÃä¾ï¦â³¡¤À)¡C´«¥y¸Ü»¡¡A¨C¤@¦ì­¼¼Æ¥h­¼¥H³Q­¼¼Æ­n¦³¥|­Ó¤p°j°é¥h³B²z¡C

¦b²Ä¤@­Ó¤j°j°éùØ¡Aµ{¦¡²Ä 178¡N179 ¦æùؤp¤ì°¸¥Î SI ¼È¦s¾¹¥h°O¿ý¥¿¦b³B²zªº­¼¼Æ¦ì§}¡A·í¨C¦¸³B²z§¹¥|­Ó¤p°j°é«á¡ASI ¼È¦s¾¹´N¼W¥[¤@¡A«ü¦V¤U¤@¦ì­¼¼Æ¡A·íµM¦b³B²z¦P¤@¦ì­¼¼Æ®É¡A³o SI ¤£¯à§ïÅÜ¡C¤p¤ì°¸¤S¥Î DI ¼È¦s¾¹¨Ó«ü¦V¼È¦s°Ï¦ì§}¡A³o­Ó¼È¦s°Ïªº¥Øªº¬O¥Î¨Ó¼È®É¦s©ñ­¼¼Æªº¨C¤@¦ì¼Æ¥h­¼³Q­¼¼Æ©Ò±oªº¼Æ­È¤§¥Î¡A¦]³o­Ó¼È¦s°Ïªº¤j¤p·|ÀH³Q­¼¼Æ»y­¼¼Æ¤§¦ì¼Æ¦³Ãö¡Aµ{¦¡³]­p®vµLªk¦b¨Æ«e¦ô­p¡A¬G¤p¤ì°¸©ñ¦bµ{¦¡ªº³Ì§ÀºÝ¡A«Ý·|¦A²Ó»¡¡C

¦n¤F¡Aµ{¦¡²Ä 183 ¦Ü 190 ¦æ¬O³B²z¤p¦ì¼Æªº¶ñ¹s³¡¤À¡Q²Ä 192 ¦Ü 202 ¦æ¬O³B²z¬Û­¼³¡¤À¡Q²Ä 204¡N205 ¨â¦æ¬O³B²z¶i¦ì¡Q²Ä 208 ¦Ü 216 ¦æ¬O³B²z¤j¦ì¼Æªº¶ñ¹s³¡¤À¡C

­È±o¤@´£ªº¬O²Ä 192 ¦Ü 202 ¦æ¬O³B²z¬Û­¼³¡¤À¡C¦b¨C¤@¦¸­pºâ¤@¦ì­¼¼Æ­¼³Q­¼¼Æ«e³£­n¥ý¨Ï AL¡NDH Âk¹s¡A³o¨â¦æµ{¦¡¦b²Ä 180¡N181 ¦æ¡C¸Ó¦ì­¼¼Æ¬O¦b SI ©Ò«ü¦ì§}ªº¼Æ­È¡A¦Ó³Q­¼¼Æ¦ì©ó BX ©Ò«üªº¼Æ­È¡ABX ·|¥Ñ³Q­¼¼Æªº­Ó¦ì¼Æ°_¡A³v¦¸«ü¦V¤j¦ì¼Æ¡A¦Ó¨C¦¸¬Û­¼«á±o¦Ò¼{¶i¦ì¡A¶i¦ì¼Æ¦s©ó DH¡C¤p¤ì°¸·Q¨ä¥L²Ó¸`¡A¤]¤£¥ÎÂØ­z¤F¡C

¦A½Í½Í²Ä¤G­Ó¤j°j°é¡C¥­±`§^¤H¬O§Q¥Îª½¦¡¥[ªk¥Ñ­Ó¦ì¼Æ¡N¤Q¦ì¼Æ¨Ì¦¸©¹¤j¦ì¼Æ¥[¤W¥h¡A¦ý¤p¤ì°¸¬O§Q¥Î¤W¤@³¹ªº¥[ªk°Æµ{¦¡¡Aubcd_add¡A¨Ó³B²z¡C¸Ó¥[ªk°Æµ{¦¡¨C¦¸¥u¯à¨D¨â¼Æ¬Û¥[¡A©Ò¥H¤p¤ì°¸´N¨Ï¦ì©ó¨â½u¤§¶¡ªº¼Æ¨Ì¦¸©M¿n¬Û¥[¡A¨Ã¨Ï¨ä©M¦A¦s©ó¿n¤º¡A¿nªº¦ì§}¥Ñ SI ¨Ó«ü©w¡A¨â½u¤§¶¡ªº¼Æ¤§¦ì§}¥Ñ BX «ü©w¡C¥H 98765*123 ¬°¨Ò¨Ó»¡¡A´N¬O¥ý¨Ï 00296295 ©M SI ©Ò«üªº¦ì§}¬Û¥[¡A¨Ã¨Ï¨ä©M¦s©ó SI ¤¤¡AµM«á¦A¨Ï 01975300 ©M¤W­zSI ©Ò«üªº¦ì§}¬Û¥[¡A¤S¨Ï¨ä©M¦s©ó SI ¤¤¡A³Ì«á¦A¨Ï 09876500©M SI ©Ò«üªº¦ì§}¬Û¥[¡A¨Ã¨Ï¨ä©M¦s©ó SI ¤¤¡C

¦b©I¥s ubcd_add °Æµ{¦¡®É¡A¥²¶·§â³Q¥[¼Æ¡N¥[¼Æ¤Î©Mªº¦ì§}¤À§O¦s©ñ©ó AX¡NBX ¤Î DX ¼È¦s¾¹¤¤¡A¬G¬Û¥[®É¡ADX ©M AX ¬Ûµ¥¡A³£µ¥©ó SI¡A¦Ó BX ¬O¥Ñ¨â½u¤§¶¡ªº¼Æ¨Ì¦¸¼W¥[¡A¼W¥[ªº¶qµø­¼¿n¦ì¼Æ¦Ó©w¡C

¨ú±oµ{¦¡µ²§À¦ì§}

³o¨â­Ó°Æµ{¦¡¦³­Ó¦@¦Pªº¦a¤è¡A¨º´N¬O³]­pªÌµLªk¥ý¹wª¾¨Ï¥ÎªÌ·|¥Î¥h¦h¤Öªº¸ê®Æ¡A¦]¦¹µLªk¥ý³W¹º¾A·í¤j¤pªº¼È¦s°Ï¡C¹J¨ì³oºØ°ÝÃD¡A¤p¤ì°¸·Q¦³¨âºØ¤è¦¡¸Ñ¨M (¦p¦³¨ä¥L¤èªk¤]½Ð§iª¾§Ú)¡A¤@¬O¨Æ¥ý¹w³]¤@¶ô«Ü¤jªº°O¾ÐÅéªÅ¶¡Åý¨Ï¥ÎªÌºÉ±¡¿é¤J¡A¦ý¬O³o¼Ë·|¨Ï±o°õ¦æÀÉÅܤj¡C²Ä¤GºØ¤èªk´N¬O±N³o¨Ç¸ê®Æ²¾¨ìµ{¦¡³Ì«á­±¡A¦p¦¹´N¤£©È¨Ï¥ÎªÌ¿é¤J¤Ó¦h¸ê®Æ¦Ó³y¦¨µ{¦¡½X¬°¸ê®Æ©ÒÂл\¦Ó¥X¿ù(¾Ú»¡¶Â´UÀb«Èªº½w½Ä°Ï·¸¦ìªº­ì²z´N¬O¦p¦¹)¡C

¦b¦¹¤p¤ì°¸±Ä¥Î²Ä¤GºØ¤èªk¡C­n¨ú±oµ{¦¡½X³Ì«á¤@­Ó¦ì§}¡A¨ä¹ê¤£Ãø¡A¥u­n¦b­ì©lµ{¦¡³Ì«á­±¥[¤W¤@­Ó¼Ð°O¡A´N¥i¥H¥Î°²«ü¥O offset ¨ú±o¸Ó¦ì§} (©Ò¥H¨ä¹ê¼Ð°O¤]¬O¤@ºØ¦ì§})¡C¦b³o­Óµ{¦¡ªº²Ä 24 ¨ì 27 ¦æ¡A´N¬O¨ú±oµ{¦¡³Ì«á¦ì§}¨Ã¦s©ó last_ad ÅܼƤ¤¡C¦Ó²Ä 25 ¦æ¬O¦]¬°³o­Óµ{¦¡©I¥s¤F¨â­Ó¥~³¡°Æµ{¦¡¡A©Ò¥HÁÙ¥²¶·¦A¥[¤W³o¨â­Ó°Æµ{¦¡ªº¤j¤p¡A3BH ©M 39H (³o¨â­Ó°Æµ{¦¡ªº¤j¤p¥i¥H¥Ñ LIB.EXE ©Ò«Ø¥ßªº¦CªíÀɬݥX¨Ó¡A¤W¤@³¹ùتº MYASMLIB.LST ÀÉ)¡C¦Ü©ó¥[¤W 20H ¬O¯d¤@¨Ç½w½ÄªÅ¶¡¡A¨Ã¨S¦³¯S§Oªº·N¸q¡C

²ÕĶ¤èªk

³o­Óµ{¦¡ªº­ì²z¤w¸g»¡§¹¤F¡A©³¤U¨ÓÂI¨à»´ÃPªº¡A¨º´N¬O¦p¦ó²ÕĶ¥L©O¡H°²³]±z§â¤W­±µ{¦¡¦s¦¨ UBCD_MUL.ASM ÀÉ¡A¨º»ò¨Ì¤U­±¨BÆJ²ÕĶ¡G

H:\HomePage\SOURCE>..\masm50\masm ubcd_mul; [Enter]
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.


  50774 + 399578 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors

H:\HomePage\SOURCE>..\masm50\link ubcd_mul,,,myasmlib [Enter]

Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.

LINK : warning L4021: no stack segment

H:\HomePage\SOURCE>..\masm50\exe2bin ubcd_mul ubcd_mul.com [Enter]

³o¼Ë´N¥i¥H±o¨ì UBCD_MUL.COM ¥i°õ¦æÀɤF¡C³o­Óµ{¦¡¥²¶·¥Î¨ì¤W¤@³¹ªº MYASMLIB.LIB µ{¦¡®w¡A½Ð°Ñ¦Ò¤W¤@³¹ªº¤èªk»s§@¥L¡C³Ì«á¦pªG±z¸ò§Ú¤@¼Ë»{¬° ubcd_input ©M ubcd_mul ©Î³\«Ü¦³¥Î¡A¨º¤]¥i¥H§â³o¨â­Ó°Æµ{¦¡¥[¤J MYASMLIB.LIB µ{¦¡®wùØ¡C

µ²½×

¤W¤@³¹ªºµ{¦¡¤w¸g«Ü½ÆÂø¤F¡A¦Ó³o­Óµ{¦¡¤ñ¤W¤@³¹¦³¹L¤§µL¤£¤Î¡A¸g¹L¨â­Ó³o¼Ë½ÆÂøªºµ{¦¡¡A±z¦³¨S¦³¤°»ò¤ß±o©O¡H§Ú·Q³o¨â³¹ªºµ{¦¡¨ä¹ê¥u¤£¹L¬O¤â¬q¡A¨Ã«D¥Øªº¡C§Ú­n§i¶D±zªº¨Ã¤£¬O³o¨Çµ{¦¡ªº¨BÆJ¡A¦Ó¬O­±¹ï¼g§@½ÆÂøµ{¦¡®Éªº¤èªk¡A¨º´N¬O¥ý¥J²ÓÆ[¹î¡A§â¤@­Ó¤j°ÝÃD¤À¸Ñ¦¨¤p°ÝÃD¡A¦A§â¤p°ÝÃD¤À¦¨§ó¤pªº°ÝÃD¡Aª½¨ì¯à°÷¥Îµ{¦¡¼g¥X¨Ó¡A¦A¥[¥H¡y²Õ¸Ë¡z°_¨Ó´N¯à¸Ñ¨M¤j°ÝÃD¤F¡C

¦ý¸Ü¤S»¡¨Ó¤F¡AÁöµM§Ú¥D­n¥Øªº¨Ã¤£¬O§i¶D§A²Ó¸`ªº¨BÆJ¡A¤£¹L³o¨â³¹ÁÙ¬O²æ¤£¤F¥DÃD¡A­pºâ BCD ¼Æªº«ü¥O AAA¡NAAM¡NDAA µ¥µ¥¡A°²¦p±z¤£ÁA¸Ñ³o´X­Ó«ü¥O¡A¤£ÁA¸Ñ°O¾ÐÅé©w§}¡A±zÁÙ¬O¨S¦³¿ìªk¼g¥X³o¨Çµ{¦¡¡A¥u¤£¹L§Ú»{¬°³o¨Ç¬O¥½¸`¡A¨Ã«D¤j¤è¦V¡C


¦^¨ì­º­¶¡A ¨ì²Ä¤Q¤T³¹¡A ¨ì²Ä¤Q¤­³¹