The MASM Forum
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
MASM32 Downloads
Home
Help
Search
Login
Register
The MASM Forum
»
Members Gallery
»
Showcase
»
Algorithm play time
« previous
next »
Print
Pages: [
1
]
Author
Topic: Algorithm play time (Read 454 times)
hutch--
Administrator
Member
Posts: 10316
Mnemonic Driven API Grinder
Algorithm play time
«
on:
July 03, 2022, 06:31:08 PM »
This is a test piece for a technique to compare two memory operands in a convenient manner using .if blocks. First use of the new editor.
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
include \masm64\include64\masm64rt.inc
eql MACRO var1,var2
rcall iseq,var1,var2
EXITM <rax>
ENDM
geq MACRO var1,var2
rcall isge,var1,var2
EXITM <rax>
ENDM
leq MACRO var1,var2
rcall isle,var1,var2
EXITM <rax>
ENDM
lth MACRO var1,var2
rcall islt,var1,var2
EXITM <rax>
ENDM
gth MACRO var1,var2
rcall isgt,var1,var2
EXITM <rax>
ENDM
.code
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
entry_point proc
LOCAL var1 :QWORD
LOCAL var2 :QWORD
conout " ----------------------------------------",lf
conout " Simple memory comparisons for .if blocks",lf
conout " to use with both procedures and macros.",lf
conout " ----------------------------------------",lf
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
mov var1, 3
mov var2, 2
conout " proc iseq",lf
.if eql(var1,var2) == 0
conout " eql - Variables are not equal",lf
.else
conout " eql - Variables are equal",lf
.endif
mov var1, 2
mov var2, 2
.if eql(var1,var2) == 0
conout " eql - Variables are not equal",lf
.else
conout " eql - Variables are equal",lf,lf
.endif
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
mov var1, 3
mov var2, 2
conout " proc isge",lf
.if geq(var1,var2) == 0
conout " geq - Variable 2 is not greater or equal",lf
.else
conout " geq - Variable 2 is greater or equal",lf
.endif
mov var1, 3
mov var2, 4
.if geq(var1,var2) == 0
conout " geq - Variable 2 is not greater or equal",lf
.else
conout " geq - Variable 2 is greater or equal",lf,lf
.endif
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
mov var1, 3
mov var2, 4
conout " proc isle",lf
.if leq(var1,var2) == 0
conout " leq - Variable 2 is not less or equal",lf
.else
conout " leq - Variable 2 is less or equal",lf
.endif
mov var1, 4
mov var2, 3
.if leq(var1,var2) == 0
conout " leq - Variable 2 is not less or equal",lf
.else
conout " leq - Variable 2 is less or equal",lf,lf
.endif
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
mov var1, 3
mov var2, 4
conout " proc islt",lf
.if lth(var1,var2) == 0
conout " lth - Variable 2 is not less than",lf
.else
conout " lth - Variable 2 is less than",lf
.endif
mov var1, 4
mov var2, 3
.if lth(var1,var2) == 0
conout " lth - Variable 2 is not less than",lf
.else
conout " lth - Variable 2 is less than",lf,lf
.endif
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
mov var1, 4
mov var2, 3
conout " proc isgt",lf
.if gth(var1,var2) == 0
conout " gth - Variable 2 is not greater than",lf
.else
conout " gth - Variable 2 is greater than",lf
.endif
mov var1, 3
mov var2, 4
.if gth(var1,var2) == 0
conout " gth - Variable 2 is not greater than",lf
.else
conout " gth - Variable 2 is greater than",lf,lf
.endif
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
waitkey " That's all folks, press any key ...."
.exit
entry_point endp
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
NOSTACKFRAME
iseq proc ; is equal
cmp rcx, rdx
jne @F
mov rax, 1
ret
@@:
xor rax, rax
ret
iseq endp
STACKFRAME
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
NOSTACKFRAME
isle proc ; is less that or equal
cmp rcx, rdx
jle @F
mov rax, 1
ret
@@:
xor rax, rax
ret
isle endp
STACKFRAME
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
NOSTACKFRAME
isge proc ; is greater than or equal
cmp rcx, rdx
jge @F
mov rax, 1
ret
@@:
xor rax, rax
ret
isge endp
STACKFRAME
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
NOSTACKFRAME
islt proc ; is less than
cmp rcx, rdx
jl @F
mov rax, 1
ret
@@:
xor rax, rax
ret
islt endp
STACKFRAME
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
NOSTACKFRAME
isgt proc ; is greater
cmp rcx, rdx
jg @F
mov rax, 1
ret
@@:
xor rax, rax
ret
isgt endp
STACKFRAME
; «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
end
['tt]
Logged
hutch at movsd dot com
http://www.masm32.com
jj2007
Member
Posts: 13661
Assembly is fun ;-)
Re: Algorithm play time
«
Reply #1 on:
July 03, 2022, 08:08:09 PM »
10 bytes instead of 17 (and probably a tick faster)
Code:
[Select]
isle proc ; is less that or equal
cmp rcx, rdx
setg al
movzx eax, al
ret
isle endp
Logged
Masm32 Tips, Tricks and Traps
hutch--
Administrator
Member
Posts: 10316
Mnemonic Driven API Grinder
Re: Algorithm play time
«
Reply #2 on:
July 03, 2022, 08:56:53 PM »
For a total of 35 bytes, I sit up at night sobbing silently into my last bottle of GlenMorangie.
Logged
hutch at movsd dot com
http://www.masm32.com
Print
Pages: [
1
]
« previous
next »
The MASM Forum
»
Members Gallery
»
Showcase
»
Algorithm play time