算術運算符示例:
; Test7_1.asm
.386
.model flat, stdcall
include msvcrt.inc
includelib msvcrt.lib
.data
szFmt db '%d', 0DH, 0AH, 0
.code
start:
mov eax, 7 + 3
invoke crt_printf, addr szFmt, eax ;10
mov eax, 7 - 3
invoke crt_printf, addr szFmt, eax ;4
mov eax, 7 * 3
invoke crt_printf, addr szFmt, eax ;21
mov eax, 7 / 3
invoke crt_printf, addr szFmt, eax ;2
mov eax, 7 mod 3
invoke crt_printf, addr szFmt, eax ;1
mov eax, 7 / 3 + 4
invoke crt_printf, addr szFmt, eax ;6
mov eax, 7 / (3 + 4)
invoke crt_printf, addr szFmt, eax ;1
ret
end start
關系操作符(EQ、NE、LT、LE、GT、GE)示例:
;EQ: 等於
;NE: 不等於
;LT: 小於
;LE: 小於等於
;GT: 大於
;GE: 大於等於
; Test7_2.asm
.386
.model flat, stdcall
include msvcrt.inc
includelib msvcrt.lib
.data
szFmt db '%d', 0DH, 0AH, 0
.code
start:
; EQ : =
mov eax, 2 eq 1
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 eq 2
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 eq 3
invoke crt_printf, addr szFmt, eax ;0
; EQ : <>
mov eax, 2 ne 1
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 ne 2
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 ne 3
invoke crt_printf, addr szFmt, eax ;-1
; LT : <
mov eax, 2 lt 1
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 lt 2
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 lt 3
invoke crt_printf, addr szFmt, eax ;-1
; LE : <=
mov eax, 2 le 1
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 le 2
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 le 3
invoke crt_printf, addr szFmt, eax ;-1
; GT : >
mov eax, 2 gt 1
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 gt 2
invoke crt_printf, addr szFmt, eax ;0
mov eax, 2 gt 3
invoke crt_printf, addr szFmt, eax ;0
; GE : >=
mov eax, 2 ge 1
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 ge 2
invoke crt_printf, addr szFmt, eax ;-1
mov eax, 2 ge 3
invoke crt_printf, addr szFmt, eax ;0
ret
end start
邏輯操作符(AND、OR、XOR、NOT)示例:
; Test7_3.asm
.386
.model flat, stdcall
include msvcrt.inc
includelib msvcrt.lib
.data
szFmt db '%08X', 0DH, 0AH, 0
.code
start:
mov eax, 0FFFFFFFFh and 0FFFF0000h
invoke crt_printf, addr szFmt, eax ;FFFF0000
mov eax, 0FFFFFFFFh or 0FFFF0000h
invoke crt_printf, addr szFmt, eax ;FFFFFFFF
mov eax, 0FFFFFFFFh xor 0FFFF0000h
invoke crt_printf, addr szFmt, eax ;0000FFFF
mov eax, not 0FFFF0000h
invoke crt_printf, addr szFmt, eax ;0000FFFF
ret
end start