![]() |
#2
小习小习2012-10-06 16:20
|
或者通过对C语言的翻译来学习汇编呢
先发一些简单的吧
本人系自学初学 很多东西不明白 只能看到一些表面上的东西 很多原理性的东西还弄不清楚
发这个贴为的是大家讨论 希望新手有所收获 更希望大牛多给指导
那我们从Hello World!开始吧
在C语言中程序和效果图如下

#include <stdio.h>
int main(void)
{
char str[128];
printf("Please input a string: ");
gets(str);
puts(str);
return 0;
}
--int main(void)
{
char str[128];
printf("Please input a string: ");
gets(str);
puts(str);
return 0;
}
只有本站会员才能查看附件,请 登录
现在我们就用汇编来达到这个目的
楼主还看不懂反汇编代码 这个的反汇编代码光是个int 3就有无数个 嘎嘎
我们只是简单的实现与C程序同样的功能就OK了吧 呵呵
汇编的代码就效果图

;#Mode=DOS
;MASMPlus 单文件代码模板 - 纯 DOS 程序
;;; 很遗憾DOS不支持中文字符串? 大牛们有什么办法吗?
assume cs:code, ds:data, ss:stack
stack segment
db 128 dup(?)
stack ends
data segment
PutStr db 'Please input a string: ', '$'
OutStr db 128
OutLen db ?
ActualStr db 128 dup ('$')
EndPrompt db 'Press any key to continue', '$'
data ends
code segment
start: ; Segment register initialize 段寄存器初始化
mov ax, stack
mov ss, ax
mov sp, 128
mov ax, data
mov ds, ax
; Input prompt 输入提示
lea dx, PutStr
mov ah, 09h
int 21h
; begin Input string and Output it 开始输入字符串并显示出来
lea dx, OutStr
mov ah, 0ah
int 21h
; Set the Cursor 2 row 23 column 设置光标于2行23列
mov ah, 02h
mov bh, 0
mov dh, 2
mov dl, 23
int 10h
; Output it 显示输入字符串
lea dx, ActualStr
mov ah, 09h
int 21h
; Carriage-Return Line-Feed 回车换行
call crlf
; Set Cursor in 3 row 0 column 光标置于3行0列
mov ah, 02h
mov bh, 0
mov dh, 3
mov dl, 0
int 10h
; Output End Prompt 输出结束提示
lea dx, EndPrompt
mov ah, 09h
int 21h
; View the result and Return DOS 查看结果并返回DOS
mov ah, 01h
int 21h
mov ah, 4ch
int 21h
; The function of Carriage-Return Line-Feed 回车换行
crlf: mov dl, 0dh
mov ah, 02h
int 21h
mov dl, 0ah
mov ah, 02h
int 21h
ret
code ends
end start
--;MASMPlus 单文件代码模板 - 纯 DOS 程序
;;; 很遗憾DOS不支持中文字符串? 大牛们有什么办法吗?
assume cs:code, ds:data, ss:stack
stack segment
db 128 dup(?)
stack ends
data segment
PutStr db 'Please input a string: ', '$'
OutStr db 128
OutLen db ?
ActualStr db 128 dup ('$')
EndPrompt db 'Press any key to continue', '$'
data ends
code segment
start: ; Segment register initialize 段寄存器初始化
mov ax, stack
mov ss, ax
mov sp, 128
mov ax, data
mov ds, ax
; Input prompt 输入提示
lea dx, PutStr
mov ah, 09h
int 21h
; begin Input string and Output it 开始输入字符串并显示出来
lea dx, OutStr
mov ah, 0ah
int 21h
; Set the Cursor 2 row 23 column 设置光标于2行23列
mov ah, 02h
mov bh, 0
mov dh, 2
mov dl, 23
int 10h
; Output it 显示输入字符串
lea dx, ActualStr
mov ah, 09h
int 21h
; Carriage-Return Line-Feed 回车换行
call crlf
; Set Cursor in 3 row 0 column 光标置于3行0列
mov ah, 02h
mov bh, 0
mov dh, 3
mov dl, 0
int 10h
; Output End Prompt 输出结束提示
lea dx, EndPrompt
mov ah, 09h
int 21h
; View the result and Return DOS 查看结果并返回DOS
mov ah, 01h
int 21h
mov ah, 4ch
int 21h
; The function of Carriage-Return Line-Feed 回车换行
crlf: mov dl, 0dh
mov ah, 02h
int 21h
mov dl, 0ah
mov ah, 02h
int 21h
ret
code ends
end start
只有本站会员才能查看附件,请 登录
看吧 其实没有什么汇编基础只要知道几个指令的功能 寄存器的作用 及不到4个中断功能
就能实现这个目的 以前对汇编存有极大的恐惧 迟迟不敢下手 看来是不应该的啦 呵呵。
有兴趣的朋友可以看下 并指出其中的不足 给出更好的方法。。。