Lately, I have been toying the Microsoft Assembler (MASM), and solving small programming challenges in it to learn about it how works. I typically use the GNU AS assembler because its so portable across instruction sets, and open source.
MASM is really interesting because unlike GNU As, which is simply a target for gcc, MASM is from an era where programmers were the target user. To that end, MASM ships with a lot of interesting features designed to improve the experience for the user including an advanced macro system including control flow logic, a type system, macro's to build function stack frames, and call other functions. Sadly, with 64-bit assembly, some of the magic has been lost (.invoke macro abandoned).
Here is an example program I wrote with MASM to solve a Challenge to order digits in a number in reverse.
There is a UASM project that brings some of this to Linux, including support for (.invoke) macro calling functions with the SYS-V ABI.
Post your favorite assembly tools, your experiences with MASM, and what kind of Macro systems you use if any. Should I learn M4 to bake on top of GNU AS?
.CODE
option casemap:none
option prologue:PrologueDef
option epilogue:EpilogueDef
public maxpermute
;;
; @brief Permute the digits of the number such that number returned as digits
; in descending order
maxpermute proc n:qword
local digit_arr[10]:byte
; prologue automatically written
xor eax,eax
cmp rcx, 0
jz @out
; save
mov [RBP+24], rdi ; save in shadow of rdx
mov n, rcx ; save n in shadow space
; zero the digit count array (al=0 here already)
lea rdi, digit_arr
mov ecx, sizeof digit_arr
rep stosb
; Walk the number computing digits
mov rax, n
@@:
xor edx, edx ; zero edx
mov ecx, 10
div rcx ; edx contains next digit
inc BYTE PTR [digit_arr+rdx]
test rax, rax
jnz @B
; Process the digits in descending order
xor rax, rax ; accumulator
mov ecx, 9; offset to last digit
@outer:
movzx rdi,BYTE PTR [digit_arr +rcx] ; fetch digit count
@inner: ; apply 10*acc + digit transform , rdi times
test rdi, rdi
jz @continue_outer
mov r8, rax
shl r8, 3
lea rax, [rax*2]
add rax, r8
add rax, rcx
dec rdi
test rdi, rdi
jnz @inner
@continue_outer:
loop @outer
mov rdi, n
@out:
ret
maxpermute endp
END
Help with nandgame: stack machine function calls
1mon 17d ago by sopuli.xyz/u/wonderingwanderer in asm@programming.devPhosh 0.50 Released, GNOME App Aims To Help You Learn Assembly
8mon 9d ago by lemmy.zip/u/cm0002 in asm@programming.dev from www.phoronix.comvxdiff: odiff (the fastest pixel-by-pixel image visual difference tool) reimplemented in AVX512 assembly.
9mon 12d ago by programming.dev/u/Serpent7776 in asm@programming.dev from github.comx86 prefixes and escape opcodes flowchart
1y 1mon ago by programming.dev/u/soc in asm@programming.dev from soc.meMy first x86 avx program: fizzbuzz using AVX512
1y 4mon ago by programming.dev/u/Serpent7776 in asm@programming.dev from github.comReverse-engineering the arcade game Sinistar
2y 6mon ago by sopuli.xyz/u/automaticdoor75 in asm@programming.dev from nantucketebooks.comVoyager's 15 Billion Mile Software Update
2y 6mon ago by programming.dev/u/ruffsl in asm@programming.dev from youtube.comWelcome to Assembly!
3y 20d ago by programming.dev/u/chaoticAnimals in asm@programming.dev

