Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38541
  • 博文数量: 64
  • 博客积分: 2640
  • 博客等级: 少校
  • 技术积分: 670
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 13:15
文章分类
文章存档

2010年(64)

我的朋友
最近访客

分类:

2010-01-26 14:19:23

                                    .386
                                    .model    flat,stdcall
                                    option    casemap:none
                                    
include                        windows.inc
include                        kernel32.inc
includelib                kernel32.lib
include                        user32.inc
includelib                user32.lib

MAXLEN                        equ                8000

                                    .data
BigNum                        dword                1,MAXLEN dup(0)
LenBN                         dword                1
Result                        dword                0,MAXLEN dup(0)
LenR                            dword                1
Temp                            dword                2,MAXLEN dup(0)
LenT                            dword                1
Exp                                dword ?

szFileName                byte                'answer.txt',0
szFileNamei                byte                'input.txt',0
szCaption                    byte                'File err',0
szText                        byte                'Cannot create file!',0
hFile                            dword                ?
hFilei                        dword                ?
szBuffer                    byte                MAXLEN dup (0)

                                    .code
Input                            proc                addExp:dword
                                    local                Num:dword,ten:dword

                                    pushf
                                    pushad
                                    
                                    lea                    esi,Num
                                    invoke            ReadFile,hFilei,offset szBuffer,MAXLEN,esi,0
                                    
                                    mov                    ten,10
                                    xor                    ecx,ecx
                                    xor                    eax,eax
                                    xor                    ebx,ebx
Conv:                            cmp                    ecx,Num
                                    jz                    eConv
                                    
                                    mov                    bl,szBuffer[ecx]
                                    test                bl,bl
                                    jz                    eConv
                                    cmp                    bl,0ah
                                    jz                    eConv
                                    cmp                    bl,0dh
                                    jz                    eConv
                                    
                                    sub                 bl,48
                                    mul                    ten
                                    add                    eax,ebx
                                    
                                 inc                    ecx
                                 jmp                    Conv
eConv:

                                 mov                    esi,addExp
                                 mov                    [esi],eax
                                
                                 popad
                                 popf
                                 ret
Input                            endp


                                    
OutIt                            proc                BN:dword,Len:dword
                                    local                Num:dword,endl:byte

                                    pushf
                                    pushad
                                                    
                                    mov                    esi,BN
                                    lea                    edi,szBuffer
                                    add                    edi,Len
                                    dec                    edi
                                    xor                    ecx,ecx
Conv:                            cmp                    ecx,Len
                                    jz                    eConv
                                    
                                    mov                    eax,[esi]
                                    add                    al,30h
                                    mov                    [edi],al
                                    
                                    add                    esi,4
                                    dec                    edi
                                    inc                    ecx
                                    jmp                    Conv
eConv:
                                                    
                                    lea                    esi,Num
                                    invoke            WriteFile,hFile,offset szBuffer,Len,esi,0

                                    mov                    al,10
                                    mov                    endl,al
                                    invoke            WriteFile,hFile,addr endl,1,esi,0
                                    
                                    popad
                                    popf
                                    
                                    ret
OutIt                            endp                                    
                                    
                    
Multi                            proc                BigA:dword,LenA:dword,BigB:dword,LenB:dword
                                    local                ten:dword

                                    pushad
                                    pushf
                                    
                                    xor                    ecx,ecx
Init:                         cmp                    ecx,MAXLEN
                                    jz                    eInit
                                    
                                    mov                    Result[4*ecx],0
                                    
                                    inc                    ecx
                                    jmp                    Init
eInit:
                                    
                                    mov                    esi,BigA
                                    xor                    ecx,ecx
For1:                            cmp                    ecx,LenA
                                    jz                    eFor1
                                    
                                    xor                    edx,edx
                                 mov                    edi,BigB
                    For2:        cmp                    edx,LenB
                                    jz                    eFor2
                                    
                                    push                edx
                                    mov                    eax,[esi]
                                    mul                    dword ptr [edi]
                                    pop                    edx
                                    
                                    mov                    ebx,ecx
                                    add                    ebx,edx
                                    add                    Result[4*ebx],eax
                                    
                                    inc                    edx
                                    add                    edi,4            
                                    jmp                    For2
                    eFor2:
                    
                                    inc            ecx
                                    add            esi,4
                                    jmp            For1
eFor1:

                                    mov                    eax,LenA
                                    add                    eax,LenB
                                    mov                    LenR,eax
                                    
                                    lea                    esi,Result
                                    xor                    ecx,ecx
                                    mov                    ten,10
Carry:                     cmp                    ecx,LenR
                                    jz                    eCarry
                                    
                                    mov                    eax,[esi]
                                    cdq
                                    div                    ten
                                    mov                    [esi],edx
                                    add                    esi,4
                                    add                    [esi],eax
                                    
                                    inc                    ecx
                                    jmp                    Carry
eCarry:
                                    
                                    mov                    ecx,LenR
Zero:                            mov                    eax,Result[4*ecx]
                                    test                eax,eax
                                    jnz                    eZero
                                    
                                    dec                    ecx
                                 jmp                    Zero
eZero:
                                    inc                    ecx
                                    mov                    LenR,ecx
                                    
                                    popf
                                    popad
                                    ret
Multi                            endp

CopyRto                        proc                BigD:dword,addLenD:dword
                                    pushf
                                    pushad
                                    
                                    mov                 esi,addLenD
                                    mov                    eax,LenR
                                    mov                    [esi],eax
                                    
                                 lea                    esi,Result
                                    mov                    edi,BigD
                                 xor                    ecx,ecx
Copy:                            cmp                    ecx,LenR
                                    jz                    eCopy
                                    
                                    mov                    eax,[esi]
                                    mov                    [edi],eax
                                    
                                    add                    esi,4
                                    add                    edi,4
                                    inc                    ecx
                                    jmp                    Copy
eCopy:
                                    
                                    popad
                             popf
                             ret
CopyRto                        endp
                        


Calc                            proc                exp:dword
                                    local                two:dword

                                    pushf
                                    pushad
                                    
                                    mov                    eax,exp
                                    mov                    two,2
MainProc:                    test                eax,eax
                                    jz                    eMainProc
                                    
                                    cdq
                                    div                    two
                                    test                edx,edx
                                    jz                    Next2
                                    
                                    invoke            Multi,offset BigNum,LenBN,offset Temp,LenT
                                    invoke            CopyRto,offset BigNum,offset LenBN
            Next2:            invoke            Multi,offset Temp,LenT,offset Temp,LenT
                                    invoke            CopyRto,offset Temp,offset LenT
                                    jmp                    MainProc
eMainProc:

                                    popad
                                    popf
                                    ret
Calc                            endp
                                    


                                    
start:                                
                                    invoke            CreateFile,offset    szFileName,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
                                    mov                    hFile,eax
                                    
                                    cmp                    eax,INVALID_HANDLE_VALUE
                                    jnz                    next1
                                    invoke            MessageBox,0,offset szText,offset szCaption,MB_OK
                                    invoke            CloseHandle,eax
                                    jmp                    Exit
next1:                        
                                    invoke            CreateFile,offset    szFileNamei,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
                                    mov                    hFilei,eax
                                    
                                    cmp                    eax,INVALID_HANDLE_VALUE
                                    jnz                    next2
                                    invoke            MessageBox,0,offset szText,offset szCaption,MB_OK
                                    invoke            CloseHandle,eax
                                    jmp                    Exit
next2:
                                    invoke            Input,offset Exp
                                    invoke            Calc,Exp
                                    invoke            OutIt,offset BigNum,LenBN
Exit:                         invoke            ExitProcess,0
                                    end    start


阅读(368) | 评论(0) | 转发(0) |
0

上一篇:2^n汇编版

下一篇:heapsort

给主人留下些什么吧!~~