Skip to content

Commit

Permalink
APCASE2 Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
brianrhall committed May 15, 2020
1 parent 88ff5bd commit 1103470
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main()
"xorl %%ecx, %%ecx \n\t" // ECX = 0
"cpuid \n\t"
"movl %%ebx, %[eFeatures1] \n\t"
"movl $80000001h, %%eax \n\t" // EAX = 80000001h
"movl $0x80000001, %%eax \n\t" // EAX = 80000001h
"cpuid \n\t"
"movl %%edx, %[eFeatures2] \n\t"
:[features1] "=m"(features1), // outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
"xorq %%rcx, %%rcx \n\t" // RCX = 0
"cpuid \n\t"
"movq %%rbx, %[eFeatures1] \n\t"
"movq $80000001h, %%rax \n\t" // RAX = 80000001h
"movq $0x80000001, %%rax \n\t" // RAX = 80000001h
"cpuid \n\t"
"movq %%rdx, %[eFeatures2] \n\t"
:[features1] "=m"(features1), // outputs
Expand Down
2 changes: 1 addition & 1 deletion Chapter_5/Program 5.2/x86_64/Program_5.2_GAS_macOS.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ myLoop:
loop myLoop

movq $0x2000001, %rax
movq $0, %rdi
xorq %rdi, %rdi
syscall
.end
2 changes: 1 addition & 1 deletion Chapter_5/Program 5.3/x86_64/Program_5.3_GAS_macOS.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ outer:
jne outer

movq $0x2000001, %rax
movq $0, %rdi
xorq %rdi, %rdi
syscall
.end
2 changes: 1 addition & 1 deletion Chapter_5/Program 5.4/x86_64/Program_5.4_GAS_macOS.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ while_loop:
done:

movq $0x2000001, %rax
movq $0, %rdi
xorq %rdi, %rdi
syscall
.end
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions Chapter_6/Program 6.1/x86_64/Program_6.1_GAS_Linux.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Program 6.1
# Sum Program - GAS, Clang/LLVM on Linux (64-bit)
# Copyright (c) 2020 Hall & Slonka

.data
num1: .long 2
num2: .long 4

.text
.global _main, _sum
_main:

movq $10, %rax
decq %rax
movq $5, %rbx

movslq num1(%rip), %rdi
movslq num2(%rip), %rsi
callq _sum

addq %rbx, %rax
decq %rax

movq $60, %rax
xorq %rdi, %rdi
syscall

_sum:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
movq %rdi, %rax
addq %rsi, %rax
popq %rbx
popq %rbp
retq

.end
38 changes: 38 additions & 0 deletions Chapter_6/Program 6.1/x86_64/Program_6.1_GAS_macOS.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Program 6.1
# Sum Program - GAS, Clang/LLVM on macOS (64-bit)
# Copyright (c) 2020 Hall & Slonka

.data
num1: .long 2
num2: .long 4

.text
.global _main, _sum
_main:

movq $10, %rax
decq %rax
movq $5, %rbx

movslq num1(%rip), %rdi
movslq num2(%rip), %rsi
callq _sum

addq %rbx, %rax
decq %rax

movq $0x2000001, %rax
movq $0, %rdi
syscall

_sum:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
movq %rdi, %rax
addq %rsi, %rax
popq %rbx
popq %rbp
retq

.end
41 changes: 41 additions & 0 deletions Chapter_6/Program 6.1/x86_64/Program_6.1_MASM.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; Program 6.1
; Sum Program - MASM (64-bit)
; Copyright (c) 2020 Hall & Slonka

extrn ExitProcess : proc

.data
num1 DWORD 2
num2 DWORD 4

.code
_main PROC

mov rax, 10
dec rax
mov rbx, 5

movsxd rcx, num1
movsxd rdx, num2
call _sum

add rax, rbx
dec rax

mov rcx, 0
call ExitProcess
_main ENDP

_sum PROC
push rbp
push rbx
sub rsp, 20h
lea rbp, [rsp + 20h]
mov rax, rcx
add rax, rdx
lea rsp, [rbp]
pop rbx
pop rbp
ret
_sum ENDP
END
36 changes: 36 additions & 0 deletions Chapter_6/Program 6.1/x86_64/Program_6.1_NASM.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; Program 6.1
; Sum Program - NASM (64-bit)
; Copyright (c) 2020 Hall & Slonka

section .data
num1: dd 2
num2: dd 4

section .text
global _main, _sum
_main:

mov rax, 10
dec rax
mov rbx, 5

movsx rdi, DWORD [rel num1]
movsx rsi, DWORD [rel num2]
call _sum

add rax, rbx
dec rax

mov rax, 60
xor rdi, rdi
syscall

_sum:
push rbp
mov rbp, rsp
push rbx
mov rax, rdi
add rax, rsi
pop rbx
pop rbp
ret
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fldcw nearest # set desired rounding mode

fldpi # load pi on the stack
frndint # round to integer (uses rounding mode)
fists result # store from stack to memory
fists result # store from FPU stack to memory
movl result, %eax # mov rounded result to EAX

movl $1, %eax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fldcw nearest # set desired rounding mode

fldpi # load pi on the stack
frndint # round to integer (uses rounding mode)
fists result # store from stack to memory
fists result # store from FPU stack to memory
movl result, %eax # mov rounded result to EAX

pushl $0
Expand Down
2 changes: 1 addition & 1 deletion Chapter_8/Program 8.2_x87_FPU_RC/x86/Program_8.2_MASM.asm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fldcw nearest ; set desired rounding mode

fldpi ; load pi on the stack
frndint ; round to integer (uses rounding mode)
fist result ; store from stack to memory
fist result ; store from FPU stack to memory
mov eax, result ; mov rounded result to EAX

INVOKE ExitProcess, 0
Expand Down
2 changes: 1 addition & 1 deletion Chapter_8/Program 8.2_x87_FPU_RC/x86/Program_8.2_NASM.asm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fldcw [nearest] ; set desired rounding mode

fldpi ; load pi on the stack
frndint ; round to integer (uses rounding mode)
fist DWORD [result] ; store from stack to memory
fist DWORD [result] ; store from FPU stack to memory
mov eax, [result] ; mov rounded result to EAX

mov eax, 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fldcw nearest(%rip) # set desired rounding mode

fldpi # load pi on the stack
frndint # round to integer (uses rounding mode)
fistpq result(%rip) # store from stack to memory
fistpq result(%rip) # store from FPU stack to memory
movq result(%rip), %rax # mov rounded result to RAX

movq $60, %rax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fldcw nearest(%rip) # set desired rounding mode

fldpi # load pi on the stack
frndint # round to integer (uses rounding mode)
fistpq result(%rip) # store from stack to memory
fistpq result(%rip) # store from FPU stack to memory
movq result(%rip), %rax # mov rounded result to RAX

movq $0x2000001, %rax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fldcw nearest ; set desired rounding mode

fldpi ; load pi on the stack
frndint ; round to integer (uses rounding mode)
fistp result ; store from stack to memory
fistp result ; store from FPU stack to memory
mov rax, result ; mov rounded result to RAX

xor rcx, rcx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fldcw [rel nearest] ; set desired rounding mode

fldpi ; load pi on the stack
frndint ; round to integer (uses rounding mode)
fistp QWORD [rel result] ; store from stack to memory
fistp QWORD [rel result] ; store from FPU stack to memory
mov rax, [rel result] ; mov rounded result to RAX

mov rax, 60
Expand Down

0 comments on commit 1103470

Please sign in to comment.