include irvine32.inc
.data
var1 dword 4 dup(0,0,0,0);
str1 byte "请用16进制输入一个大整数(最高位为96位)",0;
str2 byte "结果为:",0;
str3 byte "请输入2的次方数(十进制--不能超过31):",0;
i dword 0;
j dword 0;
str4 byte "输入的绝对值为:",0
.code
main proc

L4:
  mov dword ptr var1+12,0;
  mov j,0;正负数的标志;0为正数,1为负数;
  mov edx,offset str3;
  call writestring;
  call crlf;
  call readint;输入2的次方数十进制
  mov cl,al;
  cmp cl,0;
  je quit;

  mov esi,offset var1
  mov edx,offset str1;
  call writestring;
  call crlf;

  add esi,8;
  mov i,0;

  ;输入大整数var1;
  ;
  L1:
    cmp i,3;
    je finally;
    call readhex;
    mov [esi],eax;
    sub esi,4;
    inc i;
    jmp L1;

finally:
    mov eax,dword ptr var1+8
    ;call writeint;
    cmp eax,80000000h;判断大整数的正负;
    jb L5;
    inc j;改变正负数标记;
    mov i,0;
    mov esi,offset var1
    ;add esi,8;

    ;取大整数的绝对值,进行运算;

        neg dword ptr [esi];
        neg dword ptr[esi+4];
        cmp dword ptr [esi],0;
        je  k1;
             sub dword ptr[esi+4],1;
        k1:
          neg dword ptr[esi+8];
          cmp dword ptr [esi+4],0;
          je k2;
          sub dword ptr[esi+8],1;
        k2:

         ;输出大整数的绝对值;
         mov esi,offset var1
         mov edx,offset str4;
         call writestring;
         call crlf;
         add esi,12;
         mov i,0;

      L8:
        cmp i,4;
         je L9;
         mov eax,[esi];
         call writehex;
         mov al,',';
         call writechar;
         sub esi,4;
         inc i;
          jmp L8;

L9:       call crlf;

L5:

    ;进行乘法运算;
  mov i,0;
  mov esi,offset var1
  add esi,8;
  L2:
     cmp i,3;
     je next;
     mov eax,[esi];
     shld [esi+4],eax,cl;
     sub esi,4;
     inc i;
      jmp L2;
  next:
     shl dword ptr var1,cl;


  ;输出运算后的结果;
     mov ecx,4;
     mov esi,offset var1
     mov edx,offset str2;
     call writestring;
     call crlf;
     add esi,12;
     cmp j,1;如果大整数是负数则要高位给1;
     jne L3;
     add dword ptr[esi],80000000h;

  L3:
     mov eax,[esi];
     call writehex;
     mov al,',';
     call writechar;
     sub esi,4;
     loop L3;

    call crlf;

    jmp L4;

quit:

exit
main endp;
end main

posted on 2013-02-25 19:03  叶城宇  阅读(284)  评论(0编辑  收藏  举报