程序代码:
data segment ;数据代码段
buf db 20,?,20 dup(?) ;struct inBuffer {
; char max_length;
; char act_length;
; char buf[20];
;}inbuffer = {20, 0, {0}};
A dw 0 ;short A = 0;
B dw 0 ;short B = 0;
result dw ? ;short result;
crlf db 0ah,0dh,'$' ;const char *crlf = "\r\n";
data ends ;数据代码段结束
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
lea dx,buf
mov ah,10
int 21h ;(&inbuffer)->buf[0] = '%';
;itoa((&inbuffer)->max_length, (&inbuffer)->buf+1, 10);
;(&inbuffer)->buf[2] = 's';
;scanf((&inbuffer)->buf, (&inbuffer)->buf);
;(&inbuffer)->act_length = strlen((&inbuffer)->buf);
inc dx
mov di,dx
mov cx,[di] ;short count = (&inbuffer)->act_length;
and cx,0ffh ;count = MAKEWORD(0, LOBYTE(count));
mov bl,16
next:
inc di ;++p;(;char *p = (&inbuffer)->buf;)
mov al,[di]
cmp al,'+' ;switch (*p) {
je jadd ;case '+': goto jadd;
cmp al,'-'
je jsub ;case '-': goto jsub;
cmp al,'Z' ;}
jle no1 ;if (*p <= 'Z') goto no1;
sub al,20h
no1:
cmp al,'9'
jle no2 ;if (*p - 0x20 <= '9') got no2;
sub al,7 ;else char ch = *p - 7;
no2:
sub al,30h
mov bh,al ;ch -= 0x30;
mov ax,A
mul bl
mov A,ax ;A *= 16;
mov al,bh
and ax,0ffh
add A,ax ;A += MAKEWORD(0, ch);
dec cx ;--count;
jmp next ;goto next;
jadd:
call proc1 ;proc1();
mov ax,A
add ax,B ;short tmp = A + B;
jmp exit ;goto exit;
jsub:
call proc1
mov ax,A
sub ax,B ;tmp = A - B;
jmp exit
exit:
mov result,ax ;result = tmp;
lea dx,crlf
mov ah,9
int 21h ;printf("\r\n");
lea bx,buf ;short *pIn = (short *)&inbuffer;
mov ax,[bx+1]
and ax,0ffh
add bx,ax ;pIn += MAKEWORD(0, LOBYTE((char *)pIn++));
mov byte ptr[bx+2],'=' ;*((char *)pIn+2) = '=';
mov byte ptr[bx+3],'$' ;*((char *)pIn+3) = '$';
lea dx,buf
add dx,2 ;pIn = (short *)((char*)&inbuffer + 2);
mov ah,9
int 21h ;puts(pIn);
mov ax,result
call display ;display(result);
mov ah,4ch
int 21h ;exit(0);
proc1 proc near
mov bl,16
dec cx ;--count;
continue:
inc di ;++p;
mov al,[di] ;ch = *p;
cmp al,'Z'
jle no5 ;if (ch == 'Z') goto no5;
sub al,20h ;else ch -= 0x20;
no5:
cmp al,'9'
jle no6 ;if (ch <= '9') goto no6;
sub al,7 ;else ch -= 7;
no6:
sub al,30h ;ch -= 0x30;
mov bh,al
mov ax,B
mul bl
mov B,ax ;B *= 16;
mov al,bh
and ax,0ffh
add B,ax ;B += MAKEWORD(0, ch);
loop continue ;while (--count);
ret ;return;
proc1 endp
display proc near ;void display(short num);
mov cx,0 ;short i = 0;
mov bx,16
continue1:
xor dx,dx
div bx ;short q = MAKEWORD(0, LOBYTE(num)) / 16;
;short r = MAKEWORD(0, LOBYTE(num)) % 16;
push dx ;*--sysstack = q;
inc cx ;i++;
cmp ax,0
jnz continue1 ;if (r != 0) goto continue1;
next1:
pop dx ;q = *++sysstack;
and dx,0ffh
add dl,30h ;q = MAKEWORD(0, LOBYTE(q) + 0x30);
cmp dl,'Z'
jle no3 ;if (LOBYTE(q) <= 'Z') goto no3;
sub dl,20h ;else q -= 0x20;
no3:
cmp dl,'9'
jle no4 ;if (LOBYTE(q) <= '9') goto no4;
add dl,7 ;else q += 7;
no4:
mov ah,02
int 21h ;putchar(LOBYTE(q));
loop next1 ;while (--i);
mov ah,01h
int 21h ;getchar();
display endp
code ends
end start
这个,你在哪里看到的代码,居然可以写的这么混,你自己再看看吧,我是不想看了