-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-mni.masm
43 lines (37 loc) · 2.04 KB
/
example-mni.masm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
; Example program demonstrating custom MNI functions
lbl main
; String example - converting to uppercase
DB $100 "hello world!" ; Define source string
MOV R1 100 ; Source address
MOV R2 200 ; Destination address
MNI String.toUpper R1 R2 ; Convert to uppercase
MOV RAX 1 ; stdout
OUT 1 $200 ; Print result
; String length example
MNI String.length R1 R3 ; Get length of original string
ADD R3 48 ; Convert to ASCII
MOV $300 R3 ; Store as character
MOV $301 0 ; Null terminate
MOV RAX 1 ; stdout
OUT 1 $300 ; Print length
; Math example - square root
MOV R4 144 ; Number to find square root of
MNI MathExt.sqrt R4 R5 ; Calculate square root
ADD R5 48 ; Convert to ASCII (assuming single digit)
MOV $400 R5 ; Store as character
MOV $401 0 ; Null terminate
OUT 1 $400 ; Print square root result
; Timestamp example
MNI Util.time R6 ; Get current timestamp
DB $500 "%Y-%m-%d %H:%M:%S" ; Date format string
MOV R7 500 ; Format string address
MOV R8 600 ; Destination address for formatted date
MNI Util.formatDate R6 R7 R8 ; Format the date
OUT 1 $600 ; Print formatted date/time
; Hex conversion example
DB $700 "FF" ; Hex string
MOV R9 700 ; Hex string address
MNI Util.hexToInt R9 R10 ; Convert hex to integer
MOV RAX 1 ; stdout
OUT 1 R10 ; Print the integer value (255)
HLT