MASM, NASM Assembler Test Code 이다.
테스트용으로만 사용하자.
NASM 의 Syscall 은 GNU/Linux 에서만 사용가능 하다.
; -------------------------------------------------------------
; @Project:
; @Purpose: Assembler Test Code
; @Author: HoJung Kim (godmode2k@hotmail.com)
; @Date: Since September 11, 2009
; @Lastest Modified:
; -------------------------------------------------------------
; @Build:
; [MASM]
; c:/masm5_0/MASM %1.asm,,,,
; c:/masm5_0/LINK %1.obj,,;
; [MASM32 BUILD]
; @16 Bit
; $ ml.exe /c /Zm %1.asm
; $ link16.exe %1.obj,,;
; @32 Bit
; $ ml.exe /coff /c %1.asm
; $ link.exe /SUBSYSTEM:CONSOLE %1.obj // {CONSOLE|WINDOWS|...}
;
; [NASM]
; $ nasm -fh
; // Linux
; $ nasm -f aout .asm
; $ ld -s -o $1 $1.o
; // Cygwin
; $ nams gnuwin32 $1.asm
; $ ld -s -o $1 /lib/crt0.o $1.o
; -------------------------------------------------------------
; -------------------------------------------------------------
; [MASM]
; -------------------------------------------------------------
; --------------------------------------------
; 16 Bit
; --------------------------------------------
;.MODEL SMALL
;.STACK 100h
;
; --------------------------------------------
; 32 Bit
; --------------------------------------------
;.386
;.MODEL flat, stdcall
; --------------------------------------------
; PRESET
; --------------------------------------------
;option casemap: none ; Upper/Lower Letter
; --------------------------------------------
; INCLUDE HEADER AND LIBRARY
; --------------------------------------------
;include .\xxx.inc ; Header
;includelib .\xxx.lib ; Library
;include .\m32v10r\ml\include\user32.inc
;include .\m32v10r\ml\include\kernel32.inc
;includelib .\m32v10r\ml\lib\user32.lib
;includelib .\m32v10r\ml\lib\kernel32.lib
;
;.DATA
; CR EQU 0Dh
; LF EQU 0Ah
; MSG DB 'STRING...!', '$', CR, LF
; MSG2 DB 'Res = ', '$'
; MSG3 DB ?, '$', CR, LF
;
;.CODE
;MAIN PROC ; 16 Bit
;_start: ; 32 Bit
; mov ax, @data
; mov ds, ax
; mov ah, 9
; lea dx, MSG
; int 21h
;
; mov ax, 4c00h
; int 21h
;MAIN ENDP
;END MAIN
;END _start
; -------------------------------------------------------------
; -------------------------------------------------------------
; [NASM]
; -------------------------------------------------------------
section .data
CR: EQU 0Dh
LF: EQU 0Ah
; Max Size
g_STR_BUF_MAX_LENGTH: EQU 255
; String
strPrompt: DB '?', CR, LF
strPromptLength: EQU $-strPrompt
;
section .bss
; Variables
bufRead: RESB g_STR_BUF_MAX_LENGTH ; Array of 255 bytes
; Macros
%macro _EXIT 1
; [NOTE]
; - Parameter Count: For fake
mov eax, 1 ; System Call
mov ebx, 0 ; [in] Parameter 0:
int 80h
%endmacro
%macro _READ 2
; [RETURN]
; @%1: String
; @%2: Length
; @eax: Length
mov eax, 3 ; System Call
mov ebx, 0 ; [in] Parameter 0: File Descriptor 0 (stdin)
mov ecx, %1 ; [out] Parameter 1: String
mov edx, %2 ; [out] Parameter 2: Length
int 80h
%endmacro
%macro _WRITE 2
; [RETURN]
; @eax: none
mov eax, 4 ; System Call
mov ebx, 1 ; [in] Parameter 0: File Descriptor 1 (stdout)
mov ecx, %1 ; [in] Parameter 1: String
mov edx, %2 ; [in] Parameter 2: Length
int 80h
%endmacro
;
section .text
global _start ; Linux
;global _main ; Cygwin
;
_start: ; Linux
;_main: ; Cygwin
_WRITE strPrompt, strPromptLength
_READ bufRead, g_STR_BUF_MAX_LENGTH
push eax
_WRITE strPrompt, strPromptLength
pop edx
_WRITE bufRead, edx
_EXIT 0
; -------------------------------------------------------------
; __EOF__
-----
Cheers,
June
목요일, 10월 01, 2009
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기