| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 704 人关注过本帖
标题:精华区代码Revision-C版本[系列三]
只看楼主 加入收藏
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
结帖率:100%
收藏
已结贴  问题点数:100 回复次数:1 
精华区代码Revision-C版本[系列三]
程序代码:
*/ -------------------------------------------------------------------------------------------
*/ 出自: 编程中国 http://www.*/ 作者(也可能是转载): 爱以走远
*/ 时间: 2007-9-7
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ 链接: http://bbs.bccn.net/viewthread.php?tid=167744&extra=page%3D2%26amp%3Bfilter%3Ddigest
*/ -------------------------------------------------------------------------------------------


;Revision Declare Modified by zaixuexi
;*/ --------------------------------------------------------------------------------------
;*/ source:http://www.
;*/ author:zaixuexi
;*/ date:  2011-11-27
;*/ email: asmedu@
;*/ revision declare:
;*/ 1.add self-estimated c source code
;*/ 2.adjust all asm source code upper-case style.
;*/ 3.keep all original code designment
;*/ --------------------------------------------------------------------------------------


;typedef unsigned char uint8_t;
;typedef unsigned short int uint16_t;
;#define _BV(bit)             (1 << (bit))
;#define ARRAY_SIZE(arr)      (sizeof(arr) / sizeof(arr)[0])
;#define CF_OFFSET            (0x01)
;#define GET_PSW              (__asm lahf)
;#define RCL(a, N, n, cf_bit)                     \
;    do {                                         \
;        uint8_t psw = GET_PSW;                   \
;        cf_bit = psw & CF_OFFSET;                \
;        a = (a>>(N-n))|((a<<n) | (cf_bit<<n));   \
;    } while (0)


DATA SEGMENT
    DAT DW 32768D,16384D,8192D,4096D,2048D,1024D,512D,256D,128D,64D,32D,16D,8D,4D,2D,1D
    ;uint16_t DAT[16] = {_BV(15), _BV(14), _BV(13), _BV(12), _BV(11), _BV(10),_BV(9), _BV(8),
    ;                    _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1),  _BV(0),};
    DATAW DW 2710H,03E8H,64H,0AH,0001H        ;uint16_t DATAW[5] = {10000, 1000, 100, 10, 1};
    TEMP DB 0                       ;uint8_t  TEMP = 0;
    TEMPDEC DW 0                    ;uint16_t TEMPDEC = 0;
DATA ENDS
;**********************************************;
;STACK SEGMENT STACK 'STACK'
;STA DB 50 DUP(?)
;STACK ENDS
;**********************************************;
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA ;,SS:STACK
START:
    MOV AX,DATA
    MOV DS,AX
    LEA BX,DAT                     ;uint16_t *pDAT = DAT;
    MOV SI,0                       ;uint16_t i = 0;
    MOV DX,0                       ;uint16_t decimal = 0;
    MOV CX,0                       ;uint16_t j = 0;
CLOOP:                             ;do-while()
    CALL ENTER_BIN ;return TEMP    ;ENTER_BIN();
NOPOP:
    CMP TEMP,1
    JE YES_1                       ;if (TEMP == 1) goto YES_1;
    CMP TEMP,0
    JE YES_0                       ;else if (TEMP == 0) goto YES_0;
    JMP EXITLOOP                   ;else goto EXITLOOP;
YES_1:
    ADD CX,WORD PTR[BX]            ;j |= *pDAT;  better instruction: or cx, word ptr[bx]
YES_0:
    INC BX
    INC BX                         ;pDAT++;
    INC SI                         ;i++;
    CMP SI,15D           
    JBE CLOOP                      ;while (i <= ARRAY_SIZE(DAT));
EXITLOOP:
    MOV DX,CX                      ;decimal = j;
    INC SI                         ;i++;
    MOV CX,SI                      ;j = i;
    RCL DX,CL                      ;uint8_t cf_bit; RCL(decimal, sizeof(decimal), (LOBYTE)j, cf_bit);
    CALL CR_LF                     ;printf("\r\n");
    CALL PRINT_DEC ;DX enter to PRINT_DEC or PRINT_HEX        ;PRINT_DEC(decimal);
    CALL CR_LF                     ;printf("\r\n");
EXIT:
    MOV AX,4C00H
    INT 21H                        ;exit(0);
;-------------------------------------------------;
    ENTER_BIN PROC NEAR ;return TEMP
    MOV AH,01H
    INT 21H                        ;uint8_t ch = getchar();
    SUB AL,30H           
    MOV TEMP,AL                    ;TEMP = ch - 0x30;
    RET                            ;return;
    ENTER_BIN ENDP
;-------------------------------------------------;
;PRINT_HEX PROC NEAR ;DX enter to PRINT_DEC or PRINT_HEX
;PRINT_HEX ENDP
;-------------------------------------------------;
    PRINT_DEC PROC NEAR ;DX enter to PRINT_DEC or PRINT_HEX
    MOV AX,DX                      ;uint16_t decimal = decimal;
    LEA BX,DATAW                   ;uint16_t *pDATAW = DATAW;
    MOV SI,0                       ;uint16_t i = 0;
    MOV CX,05H                     ;uint16_t j = 5;
PLOOP:
    XOR DX,DX                      ;uint16_t k = 0;
    DIV WORD PTR [BX+SI]           ;decimal /= pDATAW[i];
    ADD AX,30H ;get ASCII
    XCHG AX,DX
    MOV TEMPDEC,AX                 ;TEMPDEC = decimal % pDATAW[i]; k = (decimal/pDATAW[i] + 0x30);
    MOV AH,02H
    INT 21H                        ;putchar(LOBYTE(k));
    MOV AX,TEMPDEC                 ;decimal = TEMPDEC;
    INC SI
    INC SI                         ;i += 1*sizeof(uint16_t) / sizeof(uint16_t);
    LOOP PLOOP                     ;while (j--);
    RET
    PRINT_DEC ENDP
;-------------------------------------------------;
    CR_LF PROC NEAR
    MOV TEMP, DL                   ;better instruction: push dx
    MOV DL,0DH
    MOV AH,02H
    INT 21H
    MOV DL,0AH
    MOV AH,02H
    INT 21H
    MOV DL,TEMP                    ;pop dx
    RET
    CR_LF ENDP
;-------------------------------------------------;
CODE ENDS
END START
简单评论: 代码描述比较清晰
搜索更多相关主题的帖子: 编程 声明 中国 
2011-11-27 12:11
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:100 

经验积累中............
2011-11-28 07:53
快速回复:精华区代码Revision-C版本[系列三]
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026511 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved