اسم المثال مكتوب بالبداية عند ال TITLE ..
TITLE Add and Subtract, Version 2 (AddSub2.asm)
; This program adds and subtracts 32-bit integers
; and stores the sum in a variable.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
val1 dword 10000h
val2 dword 40000h
val3 dword 20000h
finalVal dword ?
.code
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov finalVal,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
------------------------------------------
TITLE Add and Subtract (AddSub.asm)
; This program adds and subtracts 32-bit integers.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
exit
main ENDP
END main
-------------------------------------------------
------------
TITLE Add and Subtract (AddSubAlt.asm)
; This program adds and subtracts 32-bit integers.
; 32-bit Protected mode version
; Last update: 2/1/02
.386
.MODEL flat,stdcall
.STACK 4096
ExitProcess PROTO,dwExitCodeWORD
DumpRegs PROTO
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main
----------------------------------------------------------
TITLE Add and Subtract (AddSubR.asm)
; This program adds and subtracts 32-bit integers.
; 16-bit Real mode version.
; Last update: 2/1/02
.MODEL small,stdcall
.STACK 4096
.386
DumpRegs PROTO
.code
main PROC
mov ax,@data ; data seg address
mov ds,ax ; copy to DS
mov es,ax ; copy to ES
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
mov ah,4Ch ; exit process
mov al,0 ; return code = 0
int 21h ; call MS-DOS function
main ENDP
END main
------------------------------------------------
نموذج :
TITLE Program Template (template.asm)
; Program De******ion:
; Author:
; Date Created:
; Last Modification Date:
INCLUDE Irvine32.inc
; (insert symbol definitions here)
.data
; (insert variables here)
.code
main PROC
; (insert executable instructions here)
exit ; exit to operating system
main ENDP
; (insert additional procedures here)
END main
-----------------------------------------
TITLE Addition and Subtraction (AddSub3.asm)
; Chapter 4 example. Demonstration of ADD, SUB,
; INC, DEC, and NEG instructions, and how
; they affect the CPU status flags.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
Rval SDWORD ?
Xval SDWORD 26
Yval SDWORD 30
Zval SDWORD 40
.code
main PROC
; INC and DEC
mov ax,1000h
inc ax ; 1001h
dec ax ; 1000h
; Expression: Rval = -Xval + (Yval - Zval)
mov eax,Xval
neg eax ; -26
mov ebx,Yval
sub ebx,Zval ; -10
add eax,ebx
mov Rval,eax ; -36
; Zero flag example:
mov cx,1
sub cx,1 ; ZF = 1
mov ax,0FFFFh
inc ax ; ZF = 1
; Sign flag example:
mov cx,0
sub cx,1 ; SF = 1
mov ax,7FFFh
add ax,2 ; SF = 1
; Carry flag example:
mov al,0FFh
add al,1 ; CF = 1, AL = 00
; Overflow flag example:
mov al,+127
add al,1 ; OF = 1
mov al,-128
sub al,1 ; OF = 1
exit
main ENDP
END main
------------------------------------
TITLE Copying a String (CopyStr.asm)
; This program copies a string.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
source BYTE "This is the source string",0
target BYTE SIZEOF source DUP(0),0
.code
main PROC
mov esi,0 ; index register
mov ecx,SIZEOF source ; loop counter
L1:
mov al,source[esi] ; get a character from source
mov target[esi],al ; store it in the target
inc esi ; move to next character
loop L1 ; repeat for entire string
exit
main ENDP
END main
-------------------------------------------
TITLE Data Transfer Examples (Moves.asm)
; Chapter 4 example. Demonstration of MOV and
; XCHG with direct and direct-offset operands.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
val1 WORD 1000h
val2 WORD 2000h
arrayB BYTE 10h,20h,30h,40h,50h
arrayW WORD 100h,200h,300h
arrayD DWORD 10000h,20000h
.code
main PROC
; MOVZX
mov bx,0A69Bh
movzx eax,bx ; EAX = 0000A69Bh
movzx edx,bl ; EDX = 0000009Bh
movzx cx,bl ; CX = 009Bh
; MOVSX
mov bx,0A69Bh
movsx eax,bx ; EAX = FFFFA69Bh
movsx edx,bl ; EDX = FFFFFF9Bh
movsx cx,bl ; CX = FF9Bh
; Memory-to-memory exchange:
mov ax,val1 ; AX = 1000h
xchg ax,val2 ; AX = 2000h, val2 = 1000h
mov val1,ax ; val1 = 2000h
; Direct-Offset Addressing (byte array):
mov al,arrayB ; AL = 10h
mov al,[arrayB+1] ; AL = 20h
mov al,[arrayB+2] ; AL = 30h
; Direct-Offset Addressing (word array):
mov ax,arrayW ; AX = 100h
mov ax,[arrayW+2] ; AX = 200h
; Direct-Offset Addressing (doubleword array):
mov eax,arrayD ; EAX = 10000h
mov eax,[arrayD+4] ; EAX = 20000h
mov eax,[arrayD+TYPE arrayD] ; EAX = 20000h
exit
main ENDP
END main
-----------------------------------------------
TITLE Operators (Operator.asm)
; Demonstration of TYPE, LENGTHOF, SIZEOF operators
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
byte1 BYTE 10,20,30
array1 WORD 30 DUP(?),0,0
array2 WORD 5 DUP(3 DUP(?))
array3 DWORD 1,2,3,4
digitStr BYTE '12345678',0
myArray BYTE 10,20,30,40,50,
60,70,80,90,100
; You can examine the following constant values
; by looking in the listing file (Operator.lst):
;---------------------------------------------
X = LENGTHOF byte1 ; 3
X = LENGTHOF array1 ; 30 + 2
X = LENGTHOF array2 ; 5 * 3
X = LENGTHOF array3 ; 4
X = LENGTHOF digitStr ; 9
X = LENGTHOF myArray ; 10
X = SIZEOF byte1 ; 1 * 3
X = SIZEOF array1 ; 2 * (30 + 2)
X = SIZEOF array2 ; 2 * (5 * 3)
X = SIZEOF array3 ; 4 * 4
X = SIZEOF digitStr ; 1 * 9
.code
main PROC
exit
main ENDP
END main
--------------------------------------------
TITLE Pointers (Pointers.asm)
; Demonstration of pointers and TYPEDEF.
; Last update: 2/1/02
INCLUDE Irvine32.inc
; Create user-defined types.
PBYTE TYPEDEF PTR BYTE ; pointer to bytes
PWORD TYPEDEF PTR WORD ; pointer to words
PDWORD TYPEDEF PTR DWORD ; pointer to doublewords
.data
arrayB BYTE 10h,20h,30h
arrayW WORD 1,2,3
arrayD DWORD 4,5,6
; Create some pointer variables.
ptr1 PBYTE arrayB
ptr2 PWORD arrayW
ptr3 PDWORD arrayD
.code
main PROC
; Use the pointers to access data.
mov esi,ptr1
mov al,[esi] ; 10h
mov esi,ptr2
mov ax,[esi] ; 1
mov esi,ptr3
mov eax,[esi] ; 4
exit
main ENDP
END main
----------------------------------
TITLE Summing an Array (SumArray.asm)
; This program sums an array of words.
; Last update: 2/1/02
INCLUDE Irvine32.inc
.data
intarray WORD 100h,200h,300h,400h
.code
main PROC
mov edi,OFFSET intarray ; address of intarray
mov ecx,LENGTHOF intarray ; loop counter
mov ax,0 ; zero the accumulator
L1:
add ax,[edi] ; add an integer
add edi,TYPE intarray ; point to next integer
loop L1 ; repeat until ECX = 0
exit
main ENDP
END main
-----------------------
يتبع >>>
مواقع النشر (المفضلة)