Skip to content

Commit 66fb214

Browse files
committed
Sum examples for FASM and GAS
1 parent fd8a10c commit 66fb214

File tree

12 files changed

+324
-0
lines changed

12 files changed

+324
-0
lines changed

BSD/share/sasm/Projects/FASMSum.asm

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
format ELF
2+
3+
section '.data' writeable
4+
a dd 0
5+
b dd 0
6+
inputFormat db "%d%d", 0
7+
outputFormat db "%d", 0
8+
9+
section '.text' executable
10+
public main
11+
extrn scanf
12+
extrn printf
13+
main:
14+
mov ebp, esp; for correct debugging
15+
push b
16+
push a
17+
push inputFormat
18+
call scanf
19+
mov eax, dword[a]
20+
add eax, dword[b]
21+
push eax
22+
push outputFormat
23+
call printf
24+
mov esp, ebp
25+
xor eax, eax
26+
ret
27+
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
format ELF64
2+
3+
section '.data' writeable
4+
a dq 0
5+
b dq 0
6+
inputFormat db "%lld%lld", 0
7+
outputFormat db "%lld", 0
8+
9+
section '.text' executable
10+
public main
11+
extrn scanf
12+
extrn printf
13+
main:
14+
mov rbp, rsp; for correct debugging
15+
sub rsp, 32
16+
and rsp, -16
17+
mov rcx, inputFormat
18+
mov rdx, a
19+
mov r8, b
20+
call scanf
21+
mov rdx, qword[a]
22+
add rdx, qword[b]
23+
mov rcx, outputFormat
24+
call printf
25+
mov rsp, rbp
26+
xor rax, rax
27+
ret
28+

BSD/share/sasm/Projects/GASSum.asm

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.data
2+
a: .long 0
3+
b: .long 0
4+
inputFormat: .asciz "%d%d"
5+
outputFormat: .asciz "%d"
6+
7+
.extern printf
8+
.extern scanf
9+
.text
10+
.global main
11+
main:
12+
movl %esp, %ebp # for correct debugging
13+
pushl $b
14+
pushl $a
15+
pushl $inputFormat
16+
call scanf
17+
movl a, %eax
18+
addl b, %eax
19+
pushl %eax
20+
pushl $outputFormat
21+
call printf
22+
movl %ebp, %esp
23+
xorl %eax, %eax
24+
ret
25+
26+

BSD/share/sasm/Projects/GASSumx64.asm

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.data
2+
a: .quad 0
3+
b: .quad 0
4+
inputFormat: .asciz "%lld%lld"
5+
outputFormat: .asciz "%lld"
6+
7+
.extern printf
8+
.extern scanf
9+
.text
10+
.global main
11+
main:
12+
movq %rsp, %rbp # for correct debugging
13+
subq $32, %rsp
14+
andq $-16, %rsp
15+
movq $inputFormat, %rcx
16+
movq $a, %rdx
17+
movq $b, %r8
18+
call scanf
19+
movq (a), %rdx
20+
addq (b), %rdx
21+
movq $outputFormat, %rcx
22+
call printf
23+
movq %rbp, %rsp
24+
xorq %rax, %rax
25+
ret
26+
27+

Linux/share/sasm/Projects/FASMSum.asm

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
format ELF
2+
3+
section '.data' writeable
4+
a dd 0
5+
b dd 0
6+
inputFormat db "%d%d", 0
7+
outputFormat db "%d", 0
8+
9+
section '.text' executable
10+
public main
11+
extrn scanf
12+
extrn printf
13+
main:
14+
mov ebp, esp; for correct debugging
15+
push b
16+
push a
17+
push inputFormat
18+
call scanf
19+
mov eax, dword[a]
20+
add eax, dword[b]
21+
push eax
22+
push outputFormat
23+
call printf
24+
mov esp, ebp
25+
xor eax, eax
26+
ret
27+
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
format ELF64
2+
3+
section '.data' writeable
4+
a dq 0
5+
b dq 0
6+
inputFormat db "%lld%lld", 0
7+
outputFormat db "%lld", 0
8+
9+
section '.text' executable
10+
public main
11+
extrn scanf
12+
extrn printf
13+
main:
14+
mov rbp, rsp; for correct debugging
15+
sub rsp, 32
16+
and rsp, -16
17+
mov rcx, inputFormat
18+
mov rdx, a
19+
mov r8, b
20+
call scanf
21+
mov rdx, qword[a]
22+
add rdx, qword[b]
23+
mov rcx, outputFormat
24+
call printf
25+
mov rsp, rbp
26+
xor rax, rax
27+
ret
28+

Linux/share/sasm/Projects/GASSum.asm

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.data
2+
a: .long 0
3+
b: .long 0
4+
inputFormat: .asciz "%d%d"
5+
outputFormat: .asciz "%d"
6+
7+
.extern printf
8+
.extern scanf
9+
.text
10+
.global main
11+
main:
12+
movl %esp, %ebp # for correct debugging
13+
pushl $b
14+
pushl $a
15+
pushl $inputFormat
16+
call scanf
17+
movl a, %eax
18+
addl b, %eax
19+
pushl %eax
20+
pushl $outputFormat
21+
call printf
22+
movl %ebp, %esp
23+
xorl %eax, %eax
24+
ret
25+
26+
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.data
2+
a: .quad 0
3+
b: .quad 0
4+
inputFormat: .asciz "%lld%lld"
5+
outputFormat: .asciz "%lld"
6+
7+
.extern printf
8+
.extern scanf
9+
.text
10+
.global main
11+
main:
12+
movq %rsp, %rbp # for correct debugging
13+
subq $32, %rsp
14+
andq $-16, %rsp
15+
movq $inputFormat, %rcx
16+
movq $a, %rdx
17+
movq $b, %r8
18+
call scanf
19+
movq (a), %rdx
20+
addq (b), %rdx
21+
movq $outputFormat, %rcx
22+
call printf
23+
movq %rbp, %rsp
24+
xorq %rax, %rax
25+
ret
26+
27+

Windows/Projects/FASMSum.asm

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
format ELF
2+
3+
section '.data' writeable
4+
a dd 0
5+
b dd 0
6+
inputFormat db "%d%d", 0
7+
outputFormat db "%d", 0
8+
9+
section '.text' executable
10+
public _main
11+
extrn _scanf
12+
extrn _printf
13+
_main:
14+
mov ebp, esp; for correct debugging
15+
push b
16+
push a
17+
push inputFormat
18+
call _scanf
19+
mov eax, dword[a]
20+
add eax, dword[b]
21+
push eax
22+
push outputFormat
23+
call _printf
24+
mov esp, ebp
25+
xor eax, eax
26+
ret
27+

Windows/Projects/FASMSumx64.asm

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
format ELF64
2+
3+
section '.data' writeable
4+
a dq 0
5+
b dq 0
6+
inputFormat db "%lld%lld", 0
7+
outputFormat db "%lld", 0
8+
9+
section '.text' executable
10+
public main
11+
extrn scanf
12+
extrn printf
13+
main:
14+
mov rbp, rsp; for correct debugging
15+
sub rsp, 32
16+
and rsp, -16
17+
mov rcx, inputFormat
18+
mov rdx, a
19+
mov r8, b
20+
call scanf
21+
mov rdx, qword[a]
22+
add rdx, qword[b]
23+
mov rcx, outputFormat
24+
call printf
25+
mov rsp, rbp
26+
xor rax, rax
27+
ret
28+

Windows/Projects/GASSum.asm

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.data
2+
a: .long 0
3+
b: .long 0
4+
inputFormat: .asciz "%d%d"
5+
outputFormat: .asciz "%d"
6+
7+
.extern _printf
8+
.extern _scanf
9+
.text
10+
.global _main
11+
_main:
12+
movl %esp, %ebp # for correct debugging
13+
pushl $b
14+
pushl $a
15+
pushl $inputFormat
16+
call _scanf
17+
movl a, %eax
18+
addl b, %eax
19+
pushl %eax
20+
pushl $outputFormat
21+
call _printf
22+
movl %ebp, %esp
23+
xorl %eax, %eax
24+
ret
25+
26+

Windows/Projects/GASSumx64.asm

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.data
2+
a: .quad 0
3+
b: .quad 0
4+
inputFormat: .asciz "%lld%lld"
5+
outputFormat: .asciz "%lld"
6+
7+
.extern printf
8+
.extern scanf
9+
.text
10+
.global main
11+
main:
12+
movq %rsp, %rbp # for correct debugging
13+
subq $32, %rsp
14+
andq $-16, %rsp
15+
movq $inputFormat, %rcx
16+
movq $a, %rdx
17+
movq $b, %r8
18+
call scanf
19+
movq (a), %rdx
20+
addq (b), %rdx
21+
movq $outputFormat, %rcx
22+
call printf
23+
movq %rbp, %rsp
24+
xorq %rax, %rax
25+
ret
26+
27+

0 commit comments

Comments
 (0)