精华区代码Revision-C版本[系列一]
我想有时间的话,把汇编的精华区的代码都通过C语言的形式表达出来,当然是在自己的能力范围之内,太难的我也搞不了,方便大家一起学习,有些代码看似很难,其实也没啥。
不管有没人看吧,反正也是熟练下自己的反汇编能力。
今天先写了第一篇。大家有好的意见也可以提出。从最早的精华开始。
;[原创]抓取屏幕内容(字符模式)
;*/ --------------------------------------------------------------------------------------
;*/ 出自: 编程中国 http://www.
;*/ 作者: zhulei1978
;*/ 时间: 2007-7-28 编程论坛首发
;*/ 声明: 尊重作者劳动,转载请保留本段文字
;*/ --------------------------------------------------------------------------------------
;Revision Declare Modified by zaixuexi
;*/ --------------------------------------------------------------------------------------
;*/ source:http://www.
;*/ author:zaixuexi
;*/ date: 2011-11-25
;*/ email: asmedu@
;*/ revision declare:
;*/ 1.add self-estimated c source code
;*/ 2.adjust all asm source code lower-case style.
;*/ 3.keep all original code designment
;*/ --------------------------------------------------------------------------------------
;输入格式:
;先输入抓取屏幕的左上角行列号,再输入抓取屏幕的右下角行列号.输入第3行要输入03
;0=<行号<=24,0=<列号<=79
;typedef unsigned char uint8_t;
;typedef signed char int8_t;
data segment
num db ?,?,?,? ;int8_t num[4];
nm1 db ?
nm2 db ?
message1 db ' row1:','$'
buf1 db 3,? ;int8_t buf1[2];
data1 db ?
data2 db ?
message2 db ' col1:','$'
buf2 db 3,? ;int8_t buf2[2];
data3 db ?
data4 db ?
message3 db ' row2:','$'
buf3 db 3,? ;int8_t buf3[2];
data5 db ?
data6 db ?
message4 db ' col2:','$'
buf4 db 3,? ;int8_t buf4[2];
data7 db ?
data8 db ?
shuju db 2000 dup(?) ;uint8_t shuju[2000];
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
lea dx,message1
mov ah,9
int 21h ;puts(" row1:");
mov dx,offset buf1
mov ah,0ah
int 21h ;gets(buf1);
mov cx,0 ;int8_t ch;
mov al,data1
sub al,30h
mov bl,10
mul bl
add cx,ax ;ch += (buf1[0] - 0x30) * 10;
mov al,data2
sub al,30h
add cx,ax ;ch += (buf1[1] - 0x30);
mov num,cl ;num[0] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
lea dx,message2
mov ah,9
int 21h ;puts(" col1:");
mov dx,offset buf2
mov ah,0ah
int 21h ;gets(buf2);
mov cx,0 ;ch = 0;
mov al,data3
sub al,30h
mul bl
add cx,ax ;ch += (buf2[0] - 0x30) * 10;
mov al,data4
sub al,30h
add cx,ax ;ch += (buf2[0] - 0x30);
mov num+1,cl ;num[1] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
lea dx,message3
mov ah,9
int 21h ;puts(" row2:");
mov dx,offset buf3
mov ah,0ah
int 21h ;gets(buf3);
mov cx,0 ;ch = 0;
mov al,data5
sub al,30h
mul bl
add cx,ax ;ch += (buf3[0] - 0x30) * 10;
mov al,data6
sub al,30h
add cx,ax ;ch += (buf3[1] - 0x30);
mov num+2,cl ;num[2] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;print("\r\n");
lea dx,message4
mov ah,9
int 21h ;puts(" col2:");
mov dx,offset buf4
mov ah,0ah
int 21h ;gets(buf4);
mov cx,0 ;ch = 0;
mov al,data7
sub al,30h
mul bl
add cx,ax ;ch += (buf4[0] - 0x30) * 10;
mov al,data8
sub al,30h
add cx,ax ;ch += (buf4[1] - 0x30);
mov num+3,cl ;num[3] = ch;
mov al,num
cmp al,0
js exit1
cmp al,25
jns exit1 ;if (num[0] < 0 || num[0] >= 25) goto exit1;
mov al,num+2
cmp al,0
js exit1
cmp al,25
jns exit1 ;if (num[2] < 0 || num[2] >= 25) goto exit1;
mov al,num+1
cmp al,0
js exit1
cmp al,80
jns exit1 ;if (num[1] < 0 || num[1] >= 80) goto exit1;
mov al,num+3
cmp al,0
js exit1
cmp al,80
jns exit1 ;if (num[3] < 0 || num[3] >= 80) goto exit1;
mov al,num
mov ah,num+2
cmp ah,al
js exit1 ;if (num[2] < num[0]) goto exit1;
mov al,num+1
mov ah,num+3
cmp ah,al
js exit1 ;if (num[3] < num[1]) goto exit1;
mov al,num
mov ah,num+2
sub ah,al
add ah,1
mov nm1,ah ;nm1 = num[2] - num[0] + 1;
mov al,num+1
mov ah,num+3
sub ah,al
add ah,1
mov nm2,ah ;nm2 = num[3] - num[1] + 1;
mov ax,0b800h
mov es,ax ;short int *vga_base = (short int *)0xb800;
mov al,num
mov bl,80
mul bl
mov bh,0
mov bl,num+1
add ax,bx
mov bl,2
mul bx
mov bx,ax ;short int pos = (num[0] * 80 + num[1]) << 1;
jmp flag1 ;goto flag1;
exit1:
jmp exit ;goto exit;
flag1:
lea si,shuju ;uint8_t *disp = shuju;
mov ch,0
mov cl,nm1
;/*******************store vga memory to shuju******************************/
again1:
push cx ;register _sys_stack_nm1 = MAKEWORD(nm1, 0);
mov cl,nm2 ;uint8_t i = nm2;
push bx ;register _sys_stack_pos = pos;
push si ;register _sys_stack_disp = disp;
again2:
mov ah,byte ptr es:[bx] ;ch = (uint8_t)vga_base[pos];
mov [si],ah
add bx,2 ;pos += 2;
add si,1 ;*disp++ = ch;
loop again2 ;while (i--);
pop si
add si,80 ;disp = shuju + 80;
pop bx
add bx,160 ;pos += 160;
pop cx ;i = nm1;
loop again1 ;while (i--);
;/*******************load vga memory from shuju*****************************/
lea si,shuju ;disp = shuju;
mov ch,0
mov cl,nm1
again3:
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
push cx ;register _sys_stack_nm1 = MAKEWORD(nm1, 0);
mov cl,nm2 ;i = nm2;
mov bx,0
push si ;register _sys_stack_disp = disp;
again4:
mov dl,[si]
mov ah,2
int 21h
add si,1 ;putchar(*disp++);
loop again4 ;while (i--);
pop si
add si,80 ;disp = shuju + 80;
pop cx ;i = nm1;
loop again3 ;while (i--);
exit:
mov ah,4ch
int 21h ;exit(0);
code ends
end start
简单评论:原作者思路和代码基本比较顺畅.就是精简度不够,也没考虑用字符串指令.;*/ --------------------------------------------------------------------------------------
;*/ 出自: 编程中国 http://www.
;*/ 作者: zhulei1978
;*/ 时间: 2007-7-28 编程论坛首发
;*/ 声明: 尊重作者劳动,转载请保留本段文字
;*/ --------------------------------------------------------------------------------------
;Revision Declare Modified by zaixuexi
;*/ --------------------------------------------------------------------------------------
;*/ source:http://www.
;*/ author:zaixuexi
;*/ date: 2011-11-25
;*/ email: asmedu@
;*/ revision declare:
;*/ 1.add self-estimated c source code
;*/ 2.adjust all asm source code lower-case style.
;*/ 3.keep all original code designment
;*/ --------------------------------------------------------------------------------------
;输入格式:
;先输入抓取屏幕的左上角行列号,再输入抓取屏幕的右下角行列号.输入第3行要输入03
;0=<行号<=24,0=<列号<=79
;typedef unsigned char uint8_t;
;typedef signed char int8_t;
data segment
num db ?,?,?,? ;int8_t num[4];
nm1 db ?
nm2 db ?
message1 db ' row1:','$'
buf1 db 3,? ;int8_t buf1[2];
data1 db ?
data2 db ?
message2 db ' col1:','$'
buf2 db 3,? ;int8_t buf2[2];
data3 db ?
data4 db ?
message3 db ' row2:','$'
buf3 db 3,? ;int8_t buf3[2];
data5 db ?
data6 db ?
message4 db ' col2:','$'
buf4 db 3,? ;int8_t buf4[2];
data7 db ?
data8 db ?
shuju db 2000 dup(?) ;uint8_t shuju[2000];
data ends
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
lea dx,message1
mov ah,9
int 21h ;puts(" row1:");
mov dx,offset buf1
mov ah,0ah
int 21h ;gets(buf1);
mov cx,0 ;int8_t ch;
mov al,data1
sub al,30h
mov bl,10
mul bl
add cx,ax ;ch += (buf1[0] - 0x30) * 10;
mov al,data2
sub al,30h
add cx,ax ;ch += (buf1[1] - 0x30);
mov num,cl ;num[0] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
lea dx,message2
mov ah,9
int 21h ;puts(" col1:");
mov dx,offset buf2
mov ah,0ah
int 21h ;gets(buf2);
mov cx,0 ;ch = 0;
mov al,data3
sub al,30h
mul bl
add cx,ax ;ch += (buf2[0] - 0x30) * 10;
mov al,data4
sub al,30h
add cx,ax ;ch += (buf2[0] - 0x30);
mov num+1,cl ;num[1] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
lea dx,message3
mov ah,9
int 21h ;puts(" row2:");
mov dx,offset buf3
mov ah,0ah
int 21h ;gets(buf3);
mov cx,0 ;ch = 0;
mov al,data5
sub al,30h
mul bl
add cx,ax ;ch += (buf3[0] - 0x30) * 10;
mov al,data6
sub al,30h
add cx,ax ;ch += (buf3[1] - 0x30);
mov num+2,cl ;num[2] = ch;
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;print("\r\n");
lea dx,message4
mov ah,9
int 21h ;puts(" col2:");
mov dx,offset buf4
mov ah,0ah
int 21h ;gets(buf4);
mov cx,0 ;ch = 0;
mov al,data7
sub al,30h
mul bl
add cx,ax ;ch += (buf4[0] - 0x30) * 10;
mov al,data8
sub al,30h
add cx,ax ;ch += (buf4[1] - 0x30);
mov num+3,cl ;num[3] = ch;
mov al,num
cmp al,0
js exit1
cmp al,25
jns exit1 ;if (num[0] < 0 || num[0] >= 25) goto exit1;
mov al,num+2
cmp al,0
js exit1
cmp al,25
jns exit1 ;if (num[2] < 0 || num[2] >= 25) goto exit1;
mov al,num+1
cmp al,0
js exit1
cmp al,80
jns exit1 ;if (num[1] < 0 || num[1] >= 80) goto exit1;
mov al,num+3
cmp al,0
js exit1
cmp al,80
jns exit1 ;if (num[3] < 0 || num[3] >= 80) goto exit1;
mov al,num
mov ah,num+2
cmp ah,al
js exit1 ;if (num[2] < num[0]) goto exit1;
mov al,num+1
mov ah,num+3
cmp ah,al
js exit1 ;if (num[3] < num[1]) goto exit1;
mov al,num
mov ah,num+2
sub ah,al
add ah,1
mov nm1,ah ;nm1 = num[2] - num[0] + 1;
mov al,num+1
mov ah,num+3
sub ah,al
add ah,1
mov nm2,ah ;nm2 = num[3] - num[1] + 1;
mov ax,0b800h
mov es,ax ;short int *vga_base = (short int *)0xb800;
mov al,num
mov bl,80
mul bl
mov bh,0
mov bl,num+1
add ax,bx
mov bl,2
mul bx
mov bx,ax ;short int pos = (num[0] * 80 + num[1]) << 1;
jmp flag1 ;goto flag1;
exit1:
jmp exit ;goto exit;
flag1:
lea si,shuju ;uint8_t *disp = shuju;
mov ch,0
mov cl,nm1
;/*******************store vga memory to shuju******************************/
again1:
push cx ;register _sys_stack_nm1 = MAKEWORD(nm1, 0);
mov cl,nm2 ;uint8_t i = nm2;
push bx ;register _sys_stack_pos = pos;
push si ;register _sys_stack_disp = disp;
again2:
mov ah,byte ptr es:[bx] ;ch = (uint8_t)vga_base[pos];
mov [si],ah
add bx,2 ;pos += 2;
add si,1 ;*disp++ = ch;
loop again2 ;while (i--);
pop si
add si,80 ;disp = shuju + 80;
pop bx
add bx,160 ;pos += 160;
pop cx ;i = nm1;
loop again1 ;while (i--);
;/*******************load vga memory from shuju*****************************/
lea si,shuju ;disp = shuju;
mov ch,0
mov cl,nm1
again3:
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h ;printf("\r\n");
push cx ;register _sys_stack_nm1 = MAKEWORD(nm1, 0);
mov cl,nm2 ;i = nm2;
mov bx,0
push si ;register _sys_stack_disp = disp;
again4:
mov dl,[si]
mov ah,2
int 21h
add si,1 ;putchar(*disp++);
loop again4 ;while (i--);
pop si
add si,80 ;disp = shuju + 80;
pop cx ;i = nm1;
loop again3 ;while (i--);
exit:
mov ah,4ch
int 21h ;exit(0);
code ends
end start