Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2708323
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: C/C++

2010-05-28 12:36:22

File second2.asm :

.386
.model flat,stdcall
option casemap:none
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\msvcrt.lib
includelib d:\masm32\lib\masm32.lib
includelib d:\masm32\lib\gdi32.lib
include d:\masm32\include\kernel32.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\windows.inc
include d:\masm32\include\gdi32.inc
include d:\masm32\include\masm32.inc
;********************************************************************
;数据段
;********************************************************************
.data
HelloMsg DB "Hello World", 0      ;*
CRLF  DB 00Ah, 00Dh, 0
ExitMsg  DB "Enter to Exit", 0
.data?
buffer  DB ?
.code
Start:
 invoke StdOut, addr HelloMsg  ;*
 invoke StdOut, addr CRLF
 invoke StdOut, addr ExitMsg
 invoke StdIn, addr buffer, 1
 invoke ExitProcess, 0        ;*
 
End Start

;********************************************************************
编译:
ml /c /coff /Cp second2.asm
link /subsystem:CONSOLE second2.obj
 
;********************************************************************

.386
.model flat,stdcall
option casemap:none
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\msvcrt.lib
includelib d:\masm32\lib\masm32.lib
includelib d:\masm32\lib\gdi32.lib
include d:\masm32\include\kernel32.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\windows.inc
include d:\masm32\include\gdi32.inc
include d:\masm32\include\masm32.inc
 ; ------------
; Local macros
; ------------
print MACRO Quoted_Text:VARARG
  LOCAL Txt
    .data
      Txt db Quoted_Text,0
    .code
  invoke StdOut,ADDR Txt
ENDM
input MACRO Quoted_Prompt_Text:VARARG
  LOCAL Txt
  LOCAL Buffer
    .data
      Txt db Quoted_Prompt_Text,0
      Buffer db 128 dup(?)
    .code
  invoke StdOut,ADDR Txt
  invoke StdIn,ADDR Buffer,LENGTHOF Buffer
  mov eax, offset Buffer
ENDM
cls MACRO
  invoke ClearScreen
ENDM
Main   PROTO
; #########################################################################
.data
  Msg1        db "Type something > ",0
  Msg2        db "You typed > ",0
; #########################################################################
.code
start:
  invoke Main
  invoke ExitProcess,0
; #########################################################################
Main proc
    LOCAL InputBuffer[128]:BYTE
  ; -------------------------------
  ; console mode library procedures
  ; -------------------------------
  ; ------------
  ; using macros
  ; ------------
    cls
    print "Console function test",13,10,13,10
    input "Enter Some Text > "
    invoke StdOut,eax           ; return address in eax
  ; ----------------
  ; using procedures
  ; ----------------
 
    invoke locate,10,10
    invoke StdOut,ADDR Msg1
    invoke StdIn,ADDR InputBuffer,LENGTHOF InputBuffer
    invoke locate,10,11
    invoke StdOut,ADDR Msg2
    invoke StdOut,ADDR InputBuffer
    ret
Main endp
; #########################################################################
    end start


.386
.model flat,stdcall
option casemap:none
includelib d:\masm32\lib\kernel32.lib
includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\msvcrt.lib
includelib d:\masm32\lib\masm32.lib
includelib d:\masm32\lib\gdi32.lib
include d:\masm32\include\kernel32.inc
include d:\masm32\include\user32.inc
include d:\masm32\include\windows.inc
include d:\masm32\include\gdi32.inc
include d:\masm32\include\masm32.inc
.data
 aHelloWorld  db 'hello world',0      ; DATA XREF: _main+30o
.code
start:
_main proc near
var_C0= byte ptr -0C0h
push    ebp
mov     ebp, esp
sub     esp, 0C0h
push    ebx
push    esi
push    edi
lea     edi, [ebp+var_C0]
mov     ecx, 30h
mov     eax, 0CCCCCCCCh
rep stosd
push    1100h           ; int
push    8899h           ; int
;call    ; fun(int,int)
add     esp, 8
push    offset aHelloWorld ; " hello world"
;call    j__printf
invoke StdOut,ADDR aHelloWorld
add     esp, 4
xor     eax, eax
pop     edi
pop     esi
pop     ebx
add     esp, 0C0h
cmp     ebp, esp
;call    j___RTC_CheckEsp
mov     esp, ebp
pop     ebp
retn
_main endp
 
end start
阅读(1790) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~