From 75b624cb0572e325cc9225218396a91959a7dc72 Mon Sep 17 00:00:00 2001 From: saku0512 Date: Sat, 24 Jan 2026 23:48:26 +0900 Subject: [PATCH] feat: add AT&T --- src-tauri/src/lib.rs | 32 +++++-- src/lib/components/ExplanationView.svelte | 83 +++++++++++++++++-- src/routes/grand/[grandId]/+page.svelte | 5 +- .../BOSS/12_TheAccumulator/collect_Att.asm | 61 ++++++++++++++ .../BOSS/12_TheAccumulator/ini_Att.asm | 17 ++++ .../BOSS/12_TheAccumulator/test.sh | 6 ++ .../01_Mov&Call/collect_Att.asm | 26 ++++++ .../01_Mov&Call/ini_Att.asm | 15 ++++ .../Phase1-Registers&ALU/01_Mov&Call/test.sh | 6 ++ .../02_Addition/collect_Att.asm | 40 +++++++++ .../02_Addition/ini_Att.asm | 15 ++++ .../Phase1-Registers&ALU/02_Addition/test.sh | 6 ++ .../03_Subtraction/collect_Att.asm | 39 +++++++++ .../03_Subtraction/ini_Att.asm | 15 ++++ .../03_Subtraction/test.sh | 6 ++ .../04_TheXORTrick/collect_Att.asm | 39 +++++++++ .../04_TheXORTrick/ini_Att.asm | 15 ++++ .../04_TheXORTrick/test.sh | 6 ++ .../05_Inc&Dec/collect_Att.asm | 46 ++++++++++ .../05_Inc&Dec/ini_Att.asm | 15 ++++ .../Phase1-Registers&ALU/05_Inc&Dec/test.sh | 6 ++ .../06_Unconditional/collect_Att.asm | 30 +++++++ .../06_Unconditional/ini_Att.asm | 15 ++++ .../06_Unconditional/test.sh | 6 ++ .../07_ZeroFlag/collect_Att.asm | 38 +++++++++ .../07_ZeroFlag/ini_Att.asm | 14 ++++ .../Phase2-Flags&Jumps/07_ZeroFlag/test.sh | 6 ++ .../08_SignFlag/collect_Att.asm | 37 +++++++++ .../08_SignFlag/ini_Att.asm | 14 ++++ .../Phase2-Flags&Jumps/08_SignFlag/test.sh | 6 ++ .../09_Comparison/collect_Att.asm | 60 ++++++++++++++ .../09_Comparison/ini_Att.asm | 15 ++++ .../Phase2-Flags&Jumps/09_Comparison/test.sh | 6 ++ .../10_Countdown/collect_Att.asm | 46 ++++++++++ .../10_Countdown/ini_Att.asm | 14 ++++ .../10_Countdown/test.sh | 6 ++ .../11_Accumulate3/collect_Att.asm | 34 ++++++++ .../11_Accumulate3/ini_Att.asm | 14 ++++ .../11_Accumulate3/test.sh | 6 ++ .../BOSS/24_TheStackMachine/collect_Att.asm | 59 +++++++++++++ .../BOSS/24_TheStackMachine/ini_Att.asm | 14 ++++ .../BOSS/24_TheStackMachine/test.sh | 6 ++ .../13_Push&Pop/collect_Att.asm | 25 ++++++ .../13_Push&Pop/ini_Att.asm | 14 ++++ .../Phase1-StackBasics/13_Push&Pop/test.sh | 6 ++ .../14_SwapTwo/collect_Att.asm | 30 +++++++ .../Phase1-StackBasics/14_SwapTwo/ini_Att.asm | 14 ++++ .../Phase1-StackBasics/14_SwapTwo/test.sh | 6 ++ .../15_Duplicate/collect_Att.asm | 26 ++++++ .../15_Duplicate/ini_Att.asm | 14 ++++ .../Phase1-StackBasics/15_Duplicate/test.sh | 6 ++ .../16_Reverse3/collect_Att.asm | 34 ++++++++ .../16_Reverse3/ini_Att.asm | 14 ++++ .../Phase2-StackAsBuffer/16_Reverse3/test.sh | 6 ++ .../17_ReverseUntil0/collect_Att.asm | 41 +++++++++ .../17_ReverseUntil0/ini_Att.asm | 15 ++++ .../17_ReverseUntil0/test.sh | 6 ++ .../18_SumFromStack/collect_Att.asm | 43 ++++++++++ .../18_SumFromStack/ini_Att.asm | 15 ++++ .../18_SumFromStack/test.sh | 6 ++ .../19_SafePop/collect_Att.asm | 47 +++++++++++ .../19_SafePop/ini_Att.asm | 15 ++++ .../Phase3-StackAlgorithms/19_SafePop/test.sh | 6 ++ .../20_RPN_AddOnly/collect_Att.asm | 37 +++++++++ .../20_RPN_AddOnly/ini_Att.asm | 14 ++++ .../20_RPN_AddOnly/test.sh | 6 ++ .../21_Sort3/collect_Att.asm | 55 ++++++++++++ .../21_Sort3/ini_Att.asm | 14 ++++ .../Phase3-StackAlgorithms/21_Sort3/test.sh | 6 ++ .../22_Rotate3/collect_Att.asm | 36 ++++++++ .../22_Rotate3/ini_Att.asm | 14 ++++ .../Phase3-StackAlgorithms/22_Rotate3/test.sh | 6 ++ .../23_MinMaxFromStack/collect_Att.asm | 68 +++++++++++++++ .../23_MinMaxFromStack/ini_Att.asm | 14 ++++ .../23_MinMaxFromStack/test.sh | 6 ++ 75 files changed, 1594 insertions(+), 16 deletions(-) create mode 100644 stages/1.The-Accumulator/BOSS/12_TheAccumulator/collect_Att.asm create mode 100644 stages/1.The-Accumulator/BOSS/12_TheAccumulator/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/ini_Att.asm create mode 100644 stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/collect_Att.asm create mode 100644 stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/ini_Att.asm create mode 100644 stages/2.The-Stack/BOSS/24_TheStackMachine/collect_Att.asm create mode 100644 stages/2.The-Stack/BOSS/24_TheStackMachine/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/ini_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/collect_Att.asm create mode 100644 stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/ini_Att.asm diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 482a9fe..55548ed 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -70,19 +70,39 @@ fn get_level_explanation(level_id: String) -> Result { } #[tauri::command] -fn get_level_ini(level_id: String) -> Result { +fn get_level_ini(level_id: String, syntax: String) -> Result { let dir = level_dir_for_id(level_id.as_str()) .ok_or_else(|| format!("Stage files not found for level: {}", level_id))?; - let p = format!("{}/ini.asm", dir); - read_stage_file(&p) + let primary = match syntax.as_str() { + "Att" => format!("{}/ini_Att.asm", dir), + _ => format!("{}/ini.asm", dir), + }; + match read_stage_file(&primary) { + Ok(s) => Ok(s), + Err(_) => { + // Backward compatible fallback + let fallback = format!("{}/ini.asm", dir); + read_stage_file(&fallback) + } + } } #[tauri::command] -fn get_level_collect(level_id: String) -> Result { +fn get_level_collect(level_id: String, syntax: String) -> Result { let dir = level_dir_for_id(level_id.as_str()) .ok_or_else(|| format!("Stage files not found for level: {}", level_id))?; - let p = format!("{}/collect.asm", dir); - read_stage_file(&p) + let primary = match syntax.as_str() { + "Att" => format!("{}/collect_Att.asm", dir), + _ => format!("{}/collect.asm", dir), + }; + match read_stage_file(&primary) { + Ok(s) => Ok(s), + Err(_) => { + // Backward compatible fallback + let fallback = format!("{}/collect.asm", dir); + read_stage_file(&fallback) + } + } } #[tauri::command] diff --git a/src/lib/components/ExplanationView.svelte b/src/lib/components/ExplanationView.svelte index 3b41a8e..aaa30b0 100644 --- a/src/lib/components/ExplanationView.svelte +++ b/src/lib/components/ExplanationView.svelte @@ -4,15 +4,37 @@ export let levelId: string | null = null; export let isCompleted: boolean = false; + export let syntax: "Intel" | "Att" = "Intel"; let explanation: string | null = null; - let collectCode: string | null = null; + let collectIntel: string | null = null; + let collectAtt: string | null = null; let loading = false; let loadingCollect = false; let error: string | null = null; let errorCollect: string | null = null; let showExplanation = false; let showSolution = false; + let solutionSyntax: "Intel" | "Att" = "Intel"; + let lastLevelId: string | null = null; + + $: currentCollect = + solutionSyntax === "Att" ? collectAtt : collectIntel; + + // レベルが切り替わったらキャッシュや表示状態をクリア(前のレベルの内容が残るのを防ぐ) + $: if (levelId !== lastLevelId) { + lastLevelId = levelId; + explanation = null; + collectIntel = null; + collectAtt = null; + error = null; + errorCollect = null; + loading = false; + loadingCollect = false; + showExplanation = false; + showSolution = false; + solutionSyntax = syntax; + } async function loadExplanation() { if (!levelId || !isCompleted) return; @@ -36,12 +58,17 @@ showExplanation = !showExplanation; } - async function loadCollect() { + async function loadCollect(targetSyntax: "Intel" | "Att") { if (!levelId || !isCompleted) return; loadingCollect = true; errorCollect = null; try { - collectCode = await invoke("get_level_collect", { levelId }); + const code: string = await invoke("get_level_collect", { + levelId, + syntax: targetSyntax, + }); + if (targetSyntax === "Att") collectAtt = code; + else collectIntel = code; } catch (e) { errorCollect = String(e); console.error("Failed to load collect.asm:", e); @@ -51,12 +78,22 @@ } function toggleSolution() { - if (!showSolution && !collectCode) { - loadCollect(); + if (!showSolution) { + solutionSyntax = syntax; + if (!currentCollect) { + loadCollect(solutionSyntax); + } } showSolution = !showSolution; } + function onChangeSolutionSyntax(next: "Intel" | "Att") { + solutionSyntax = next; + if (!currentCollect) { + loadCollect(solutionSyntax); + } + } + // Markdownを簡単にレンダリング(基本的な処理) function formatMarkdown(text: string): string { let formatted = text; @@ -119,10 +156,21 @@
模範解答を読み込んでいます...
{:else if errorCollect}
模範解答の読み込みに失敗しました: {errorCollect}
- {:else if collectCode} + {:else if currentCollect}
-

模範解答(collect.asm)

-
{collectCode.trim()}
+
+

模範解答(collect.asm)

+ +
+
{currentCollect.trim()}
{/if} @@ -140,6 +188,25 @@ gap: 0.75rem; } + .solution-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; + } + + .syntax-select { + background: rgba(0, 0, 0, 0.25); + color: #94a3b8; + border: 1px solid rgba(255, 255, 255, 0.12); + padding: 0.45rem 0.75rem; + border-radius: 10px; + font-family: "Fira Code", monospace; + font-size: 0.75rem; + cursor: pointer; + outline: none; + } + .explanation-toggle { display: flex; align-items: center; diff --git a/src/routes/grand/[grandId]/+page.svelte b/src/routes/grand/[grandId]/+page.svelte index afe6d00..d7dca4a 100644 --- a/src/routes/grand/[grandId]/+page.svelte +++ b/src/routes/grand/[grandId]/+page.svelte @@ -16,7 +16,7 @@ markLevelComplete, } from "$lib/progress"; - let syntax = "Intel"; + let syntax: "Intel" | "Att" = "Intel"; let code = `section .bss buf resb 16 @@ -114,7 +114,7 @@ _start: async function applyDefaultCode(levelId: string) { // 可能ならステージごとの ini.asm を初期コードとして読み込む try { - const ini: string = await invoke("get_level_ini", { levelId }); + const ini: string = await invoke("get_level_ini", { levelId, syntax }); code = ini; return; } catch (e) { @@ -289,6 +289,7 @@ _start: {/if} diff --git a/stages/1.The-Accumulator/BOSS/12_TheAccumulator/collect_Att.asm b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/collect_Att.asm new file mode 100644 index 0000000..18964ce --- /dev/null +++ b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/collect_Att.asm @@ -0,0 +1,61 @@ +section .bss + buf resb 32 + out resb 32 + +section .text + global _start + +_start: + # read(0, buf, 32) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $32, %rdx + syscall + + movq %rax, %rcx + movq $buf, %r15 + movq $out, %r14 + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done + + movb (%r15,%r8,1), %al + + # uppercase? + cmpb $0x41, %al + jl .check_digit + cmpb $0x5a, %al + jg .check_digit + addb $0x20, %al + jmp .write + +.check_digit: + cmpb $0x30, %al + jl .write + cmpb $0x39, %al + jg .write + incb %al + cmpb $0x3a, %al + jne .write + movb $0x30, %al + +.write: + movb %al, (%r14,%r8,1) + incq %r8 + jmp .loop + +.done: + # write(1, out, rcx) + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq %r14, %rsi + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/BOSS/12_TheAccumulator/ini_Att.asm b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/ini_Att.asm new file mode 100644 index 0000000..a44eb04 --- /dev/null +++ b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/ini_Att.asm @@ -0,0 +1,17 @@ +section .bss + buf resb 32 + out resb 32 + +section .text + global _start + +_start: + # MISSION: The Accumulator (BOSS STAGE) + # - A-Z -> a-z + # - 0-9 -> increment (wrap 9->0) + # - others unchanged + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/BOSS/12_TheAccumulator/test.sh b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/test.sh index 97af285..1f33905 100644 --- a/stages/1.The-Accumulator/BOSS/12_TheAccumulator/test.sh +++ b/stages/1.The-Accumulator/BOSS/12_TheAccumulator/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "12_TheAccumulator" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "12_TheAccumulator" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/collect_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/collect_Att.asm new file mode 100644 index 0000000..4554a04 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/collect_Att.asm @@ -0,0 +1,26 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + # write(1, buf, rax) + movq %rax, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/ini_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/ini_Att.asm new file mode 100644 index 0000000..848efd0 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Mov & Call + # read from stdin (syscall 0), write to stdout (syscall 1) + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/test.sh b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/test.sh index 4133e8e..6e1f18e 100644 --- a/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/test.sh +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/01_Mov&Call/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "01_Mov&Call" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "01_Mov&Call" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/collect_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/collect_Att.asm new file mode 100644 index 0000000..7069c8e --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/collect_Att.asm @@ -0,0 +1,40 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + # rcx = bytes read, r8 = index + movq %rax, %rcx + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done_add + movb buf(%r8), %al + addb $1, %al + movb %al, buf(%r8) + incq %r8 + jmp .loop + +.done_add: + # write(1, buf, rcx) + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/ini_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/ini_Att.asm new file mode 100644 index 0000000..d8a9948 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Addition + # read from stdin, add 1 to each byte, write to stdout + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/test.sh b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/test.sh index c24a5ed..fefa235 100644 --- a/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/test.sh +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/02_Addition/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "02_Addition" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "02_Addition" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/collect_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/collect_Att.asm new file mode 100644 index 0000000..6e8e728 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/collect_Att.asm @@ -0,0 +1,39 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq %rax, %rcx + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done_sub + movb buf(%r8), %al + subb $1, %al + movb %al, buf(%r8) + incq %r8 + jmp .loop + +.done_sub: + # write(1, buf, rcx) + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/ini_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/ini_Att.asm new file mode 100644 index 0000000..1342ebc --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Subtraction + # read from stdin, subtract 1 from each byte, write to stdout + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/test.sh b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/test.sh index 8d70ba9..6bc0ec8 100644 --- a/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/test.sh +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/03_Subtraction/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "03_Subtraction" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "03_Subtraction" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/collect_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/collect_Att.asm new file mode 100644 index 0000000..f51631f --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/collect_Att.asm @@ -0,0 +1,39 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq %rax, %rcx + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done_xor + movb buf(%r8), %al + xorb $0x20, %al + movb %al, buf(%r8) + incq %r8 + jmp .loop + +.done_xor: + # write(1, buf, rcx) + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/ini_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/ini_Att.asm new file mode 100644 index 0000000..530c6e7 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: The XOR Trick + # read from stdin, XOR each byte with 0x20, write to stdout + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/test.sh b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/test.sh index a6e0962..2f64009 100644 --- a/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/test.sh +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/04_TheXORTrick/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "04_TheXORTrick" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "04_TheXORTrick" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/collect_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/collect_Att.asm new file mode 100644 index 0000000..fcca7e1 --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/collect_Att.asm @@ -0,0 +1,46 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq %rax, %rcx + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done_inc_dec + movb buf(%r8), %al + testq $1, %r8 + jnz .do_dec +.do_inc: + incb %al + jmp .next +.do_dec: + decb %al +.next: + movb %al, buf(%r8) + incq %r8 + jmp .loop + +.done_inc_dec: + # write(1, buf, rcx) + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/ini_Att.asm b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/ini_Att.asm new file mode 100644 index 0000000..537b30a --- /dev/null +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Inc & Dec + # read from stdin, inc even-indexed, dec odd-indexed bytes, write to stdout + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/test.sh b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/test.sh index 4d97425..155460c 100644 --- a/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/test.sh +++ b/stages/1.The-Accumulator/Phase1-Registers&ALU/05_Inc&Dec/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "05_Inc&Dec" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "05_Inc&Dec" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/collect_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/collect_Att.asm new file mode 100644 index 0000000..0e44f27 --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/collect_Att.asm @@ -0,0 +1,30 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + jmp .read_input + +.read_input: + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + jmp .write_output + +.write_output: + movq %rax, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + jmp .exit + +.exit: + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/ini_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/ini_Att.asm new file mode 100644 index 0000000..eb2226a --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Unconditional + # read from stdin, write to stdout using jmp + + # exit(0) + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/test.sh b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/test.sh index 83da833..5be5b18 100644 --- a/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/test.sh +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/06_Unconditional/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "06_Unconditional" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "06_Unconditional" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/collect_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/collect_Att.asm new file mode 100644 index 0000000..77e2c14 --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/collect_Att.asm @@ -0,0 +1,38 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq %rax, %rcx + xorq %r8, %r8 + +.loop: + cmpq %rcx, %r8 + jge .done_replace + movb buf(%r8), %al + cmpb $0, %al + jne .next + movb $0x20, buf(%r8) +.next: + incq %r8 + jmp .loop + +.done_replace: + movq %rcx, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/ini_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/ini_Att.asm new file mode 100644 index 0000000..552d341 --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Zero Flag + # read from stdin, replace null bytes with spaces, write to stdout + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/test.sh b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/test.sh index 9ce93ae..e32cbd4 100644 --- a/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/test.sh +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/07_ZeroFlag/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "07_ZeroFlag" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "07_ZeroFlag" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/collect_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/collect_Att.asm new file mode 100644 index 0000000..624c38f --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/collect_Att.asm @@ -0,0 +1,37 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + # if first byte is negative -> '-', else '+' + movq $buf, %r15 + movb (%r15), %al + testb %al, %al + js .is_negative + + movb $0x2b, (%r15) # '+' + jmp .write_result + +.is_negative: + movb $0x2d, (%r15) # '-' + +.write_result: + movq $1, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/ini_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/ini_Att.asm new file mode 100644 index 0000000..93ba270 --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Sign Flag + # read from stdin, check if first byte is negative, write result + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/test.sh b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/test.sh index 93d46af..7a94f9f 100644 --- a/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/test.sh +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/08_SignFlag/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "08_SignFlag" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "08_SignFlag" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/collect_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/collect_Att.asm new file mode 100644 index 0000000..2b33dca --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/collect_Att.asm @@ -0,0 +1,60 @@ +section .bss + buf resb 16 + out resb 16 + +section .text + global _start + +_start: + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq %rax, %rcx + cmpq $2, %rcx + jl .exit + + movq $buf, %r15 + movq $out, %r14 + xorq %r8, %r8 # index + movb (%r15), %al # prev + xorq %r9, %r9 # out index + +.loop: + incq %r8 + cmpq %rcx, %r8 + jge .done + + movb (%r15,%r8,1), %bl # cur + cmpb %al, %bl # cur - prev + je .eq + jg .gt + +.lt: + movb $0x2d, (%r14,%r9,1) # '-' + jmp .next +.eq: + movb $0x3d, (%r14,%r9,1) # '=' + jmp .next +.gt: + movb $0x2b, (%r14,%r9,1) # '+' + +.next: + movb %bl, %al + incq %r9 + jmp .loop + +.done: + movq %r9, %rdx + movq $1, %rax + movq $1, %rdi + movq %r14, %rsi + syscall + +.exit: + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/ini_Att.asm b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/ini_Att.asm new file mode 100644 index 0000000..e024a4b --- /dev/null +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + out resb 16 + +section .text + global _start + +_start: + # MISSION: Comparison + # read from stdin, compare consecutive bytes, output +/=/- markers + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/test.sh b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/test.sh index 64bd512..9c73050 100644 --- a/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/test.sh +++ b/stages/1.The-Accumulator/Phase2-Flags&Jumps/09_Comparison/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "09_Comparison" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "09_Comparison" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/collect_Att.asm b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/collect_Att.asm new file mode 100644 index 0000000..cb67362 --- /dev/null +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/collect_Att.asm @@ -0,0 +1,46 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 1) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + # n = buf[0] - '0' + movq $buf, %r15 + movb (%r15), %al + subb $0x30, %al + + # rcx = n + 1 (include 0) + xorq %rcx, %rcx + movb %al, %cl + incq %rcx + + xorq %r8, %r8 + +.loop: + movb %cl, %al + decb %al + addb $0x30, %al + movb %al, buf(%r8) + incq %r8 + decq %rcx + jnz .loop + + # write(1, buf, r8) + movq %r8, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/ini_Att.asm b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/ini_Att.asm new file mode 100644 index 0000000..b6505f2 --- /dev/null +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Countdown + # read a digit, count down from it to '0' + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/test.sh b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/test.sh index 5f50a49..fdd7347 100644 --- a/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/test.sh +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/10_Countdown/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "10_Countdown" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "10_Countdown" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/collect_Att.asm b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/collect_Att.asm new file mode 100644 index 0000000..f41860f --- /dev/null +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/collect_Att.asm @@ -0,0 +1,34 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # read(0, buf, 16) + movq $0, %rax + movq $0, %rdi + movq $buf, %rsi + movq $16, %rdx + syscall + + movq $buf, %r15 + xorl %eax, %eax + movb (%r15), %al + movb 1(%r15), %bl + addb %bl, %al + movb 2(%r15), %bl + addb %bl, %al + movb %al, (%r15) + + # write(1, buf, 1) + movq $1, %rdx + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/ini_Att.asm b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/ini_Att.asm new file mode 100644 index 0000000..ef58b1c --- /dev/null +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Accumulate 3 + # read input, sum the first 3 bytes (u8), write 1 byte result + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/test.sh b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/test.sh index 0f959ba..85e0abc 100644 --- a/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/test.sh +++ b/stages/1.The-Accumulator/Phase3-LoopStructures/11_Accumulate3/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "11_Accumulate3" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "11_Accumulate3" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/BOSS/24_TheStackMachine/collect_Att.asm b/stages/2.The-Stack/BOSS/24_TheStackMachine/collect_Att.asm new file mode 100644 index 0000000..fd2bfdd --- /dev/null +++ b/stages/2.The-Stack/BOSS/24_TheStackMachine/collect_Att.asm @@ -0,0 +1,59 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: +.loop: + in %rax + cmpq $0, %rax + je .done + js .op + pushq %rax + jmp .loop + +.op: + cmpq $-1, %rax + je .do_add + cmpq $-2, %rax + je .do_sub + cmpq $-3, %rax + je .do_xor + jmp .loop + +.do_add: + popq %rbx + popq %rcx + addq %rbx, %rcx + pushq %rcx + jmp .loop + +.do_sub: + popq %rbx + popq %rcx + subq %rbx, %rcx + pushq %rcx + jmp .loop + +.do_xor: + popq %rbx + popq %rcx + xorq %rbx, %rcx + pushq %rcx + jmp .loop + +.done: + popq %rax + movq $buf, %rsi + movq %rax, (%rsi) + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/BOSS/24_TheStackMachine/ini_Att.asm b/stages/2.The-Stack/BOSS/24_TheStackMachine/ini_Att.asm new file mode 100644 index 0000000..055327a --- /dev/null +++ b/stages/2.The-Stack/BOSS/24_TheStackMachine/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: The Stack Machine (BOSS) + # トークン列を評価し、最後の結果をsys_writeで出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/BOSS/24_TheStackMachine/test.sh b/stages/2.The-Stack/BOSS/24_TheStackMachine/test.sh index fdeb442..de23f14 100644 --- a/stages/2.The-Stack/BOSS/24_TheStackMachine/test.sh +++ b/stages/2.The-Stack/BOSS/24_TheStackMachine/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "24_TheStackMachine" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "24_TheStackMachine" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/collect_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/collect_Att.asm new file mode 100644 index 0000000..5da898d --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/collect_Att.asm @@ -0,0 +1,25 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + pushq %rax + xorq %rax, %rax + popq %rax + + movq $buf, %rsi + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/ini_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/ini_Att.asm new file mode 100644 index 0000000..9d0400d --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Push & Pop + # INで値を1つ読み、pushで退避し、popで復元してsys_writeで出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/test.sh b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/test.sh index 7dfc793..2f732c1 100644 --- a/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/test.sh +++ b/stages/2.The-Stack/Phase1-StackBasics/13_Push&Pop/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "13_Push&Pop" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "13_Push&Pop" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/collect_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/collect_Att.asm new file mode 100644 index 0000000..33ce286 --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/collect_Att.asm @@ -0,0 +1,30 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + pushq %rax + + in %rax + pushq %rax + + movq $buf, %rsi + popq %rax + movq %rax, (%rsi) + incq %rsi + popq %rax + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $2, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/ini_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/ini_Att.asm new file mode 100644 index 0000000..54c59e7 --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Swap Two + # INで A, B を読み、sys_writeで B, A の順に出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/test.sh b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/test.sh index 0247b50..7eaacb2 100644 --- a/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/test.sh +++ b/stages/2.The-Stack/Phase1-StackBasics/14_SwapTwo/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "14_SwapTwo" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "14_SwapTwo" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/collect_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/collect_Att.asm new file mode 100644 index 0000000..2b90375 --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/collect_Att.asm @@ -0,0 +1,26 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + pushq %rax + + popq %rbx + movq $buf, %rsi + movq %rbx, (%rsi) + incq %rsi + movq %rbx, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $2, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/ini_Att.asm b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/ini_Att.asm new file mode 100644 index 0000000..35321fe --- /dev/null +++ b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Duplicate + # INで A を読み、sys_writeで A, A を出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/test.sh b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/test.sh index 170664f..035bbc8 100644 --- a/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/test.sh +++ b/stages/2.The-Stack/Phase1-StackBasics/15_Duplicate/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "15_Duplicate" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "15_Duplicate" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/collect_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/collect_Att.asm new file mode 100644 index 0000000..22c0309 --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/collect_Att.asm @@ -0,0 +1,34 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + pushq %rax + in %rax + pushq %rax + in %rax + pushq %rax + + movq $buf, %rsi + popq %rax + movq %rax, (%rsi) + incq %rsi + popq %rax + movq %rax, (%rsi) + incq %rsi + popq %rax + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $3, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/ini_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/ini_Att.asm new file mode 100644 index 0000000..5014a8e --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Reverse 3 + # INで A, B, C を読み、sys_writeで C, B, A を出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/test.sh b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/test.sh index 1e6a0fd..bf1236d 100644 --- a/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/test.sh +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/16_Reverse3/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "16_Reverse3" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "16_Reverse3" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/collect_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/collect_Att.asm new file mode 100644 index 0000000..2959bd2 --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/collect_Att.asm @@ -0,0 +1,41 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + xorq %rcx, %rcx + +.read_loop: + in %rax + cmpq $0, %rax + je .read_done + pushq %rax + incq %rcx + jmp .read_loop + +.read_done: + movq %rcx, %r9 + movq $buf, %rsi + +.out_loop: + cmpq $0, %rcx + je .do_write + popq %rax + movq %rax, (%rsi) + incq %rsi + decq %rcx + jmp .out_loop + +.do_write: + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq %r9, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/ini_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/ini_Att.asm new file mode 100644 index 0000000..f65ab74 --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Reverse Until 0 + # INで値を読み続け、0が来たら終了 + # それまでの値を逆順で sys_write する(0は出力しない) + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/test.sh b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/test.sh index 133c76f..8b78bac 100644 --- a/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/test.sh +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/17_ReverseUntil0/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "17_ReverseUntil0" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "17_ReverseUntil0" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/collect_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/collect_Att.asm new file mode 100644 index 0000000..6bcb306 --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/collect_Att.asm @@ -0,0 +1,43 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + xorq %rcx, %rcx + +.read_loop: + in %rax + cmpq $0, %rax + je .read_done + pushq %rax + incq %rcx + jmp .read_loop + +.read_done: + xorq %rbx, %rbx + +.sum_loop: + cmpq $0, %rcx + je .done + popq %rax + addq %rax, %rbx + decq %rcx + jmp .sum_loop + +.done: + movq %rbx, %rax + + movq $buf, %rsi + movq %rax, (%rsi) + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/ini_Att.asm b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/ini_Att.asm new file mode 100644 index 0000000..65738ea --- /dev/null +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Sum From Stack + # INで 0 が来るまで読み、全てをpush + # その後 pop しながら合計し、sys_writeで出力する(0は含めない) + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/test.sh b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/test.sh index 1b4649e..595bfaa 100644 --- a/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/test.sh +++ b/stages/2.The-Stack/Phase2-StackAsBuffer/18_SumFromStack/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "18_SumFromStack" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "18_SumFromStack" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/collect_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/collect_Att.asm new file mode 100644 index 0000000..e7cf939 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/collect_Att.asm @@ -0,0 +1,47 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + xorq %rcx, %rcx + +.loop: + in %rax + cmpq $0, %rax + je .done + cmpq $1, %rax + je .do_push + cmpq $-1, %rax + je .do_pop + jmp .loop + +.do_push: + in %rax + pushq %rax + incq %rcx + jmp .loop + +.do_pop: + cmpq $0, %rcx + je .loop + popq %rbx + decq %rcx + jmp .loop + +.done: + movq %rcx, %rax + movq $buf, %rsi + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/ini_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/ini_Att.asm new file mode 100644 index 0000000..1585023 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/ini_Att.asm @@ -0,0 +1,15 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Safe Pop + # トークン列を処理して、空popを防ぐ + # 最終的な深さを sys_write で出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/test.sh b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/test.sh index 5164c6c..8418662 100644 --- a/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/test.sh +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/19_SafePop/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "19_SafePop" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "19_SafePop" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/collect_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/collect_Att.asm new file mode 100644 index 0000000..ad98f38 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/collect_Att.asm @@ -0,0 +1,37 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: +.loop: + in %rax + cmpq $0, %rax + je .done + cmpq $-1, %rax + je .add + pushq %rax + jmp .loop + +.add: + popq %rbx + popq %rcx + addq %rbx, %rcx + pushq %rcx + jmp .loop + +.done: + popq %rax + movq $buf, %rsi + movq %rax, (%rsi) + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $1, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/ini_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/ini_Att.asm new file mode 100644 index 0000000..df5f889 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: RPN (Add Only) + # RPNトークン列を処理し、最後にtopをsys_writeで出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/test.sh b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/test.sh index ff4da85..84f37ca 100644 --- a/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/test.sh +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/20_RPN_AddOnly/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "20_RPN_AddOnly" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "20_RPN_AddOnly" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/collect_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/collect_Att.asm new file mode 100644 index 0000000..2d26550 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/collect_Att.asm @@ -0,0 +1,55 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + in %rbx + in %rcx + + # if A > B then swap(A,B) + cmpq %rbx, %rax + js .ab_ok + je .ab_ok + pushq %rax + movq %rbx, %rax + popq %rbx +.ab_ok: + + # if B > C then swap(B,C) + cmpq %rcx, %rbx + js .bc_ok + je .bc_ok + pushq %rbx + movq %rcx, %rbx + popq %rcx +.bc_ok: + + # again: if A > B then swap(A,B) + cmpq %rbx, %rax + js .ab2_ok + je .ab2_ok + pushq %rax + movq %rbx, %rax + popq %rbx +.ab2_ok: + + movq $buf, %rsi + movq %rax, (%rsi) + incq %rsi + movq %rbx, (%rsi) + incq %rsi + movq %rcx, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $3, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/ini_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/ini_Att.asm new file mode 100644 index 0000000..3231e54 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Sort 3 + # INで3値を読み、昇順にして sys_write する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/test.sh b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/test.sh index 0683e14..c3fd04b 100644 --- a/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/test.sh +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/21_Sort3/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "21_Sort3" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "21_Sort3" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/collect_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/collect_Att.asm new file mode 100644 index 0000000..713db40 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/collect_Att.asm @@ -0,0 +1,36 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + in %rax + pushq %rax + in %rax + pushq %rax + in %rax + pushq %rax + + popq %r8 + + movq $buf, %rsi + popq %rax + movq %rax, (%rsi) + incq %rsi + movq %r8, %rax + movq %rax, (%rsi) + incq %rsi + popq %rax + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $3, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/ini_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/ini_Att.asm new file mode 100644 index 0000000..2614f5c --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Rotate 3 + # INで A,B,C を読み、sys_writeで B,C,A を出力する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/test.sh b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/test.sh index 8073af0..74e85f8 100644 --- a/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/test.sh +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/22_Rotate3/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "22_Rotate3" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "22_Rotate3" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/collect_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/collect_Att.asm new file mode 100644 index 0000000..3404977 --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/collect_Att.asm @@ -0,0 +1,68 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + xorq %rcx, %rcx + +.read_loop: + in %rax + cmpq $0, %rax + je .read_done + pushq %rax + incq %rcx + jmp .read_loop + +.read_done: + popq %rbx + movq %rbx, %r8 # min + movq %rbx, %r9 # max + decq %rcx + +.loop: + cmpq $0, %rcx + je .do_write + + popq %rbx + + # if rbx < min then min = rbx + movq %rbx, %rax + subq %r8, %rax + js .update_min + jmp .check_max + +.update_min: + movq %rbx, %r8 + +.check_max: + # if rbx > max then max = rbx + movq %rbx, %rax + subq %r9, %rax + js .next + je .next + movq %rbx, %r9 + +.next: + decq %rcx + jmp .loop + +.do_write: + movq $buf, %rsi + movq %r8, %rax + movq %rax, (%rsi) + incq %rsi + movq %r9, %rax + movq %rax, (%rsi) + + movq $1, %rax + movq $1, %rdi + movq $buf, %rsi + movq $2, %rdx + syscall + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/ini_Att.asm b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/ini_Att.asm new file mode 100644 index 0000000..620b1ec --- /dev/null +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/ini_Att.asm @@ -0,0 +1,14 @@ +section .bss + buf resb 16 + +section .text + global _start + +_start: + # MISSION: Min & Max From Stack + # 0が来るまで値を読み、最後に min と max を sys_write する + + movq $60, %rax + xorq %rdi, %rdi + syscall + diff --git a/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/test.sh b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/test.sh index 17874fb..1833135 100644 --- a/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/test.sh +++ b/stages/2.The-Stack/Phase3-StackAlgorithms/23_MinMaxFromStack/test.sh @@ -6,5 +6,11 @@ STAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ --level-id "23_MinMaxFromStack" \ + --syntax Intel \ --asm "$STAGE_DIR/collect.asm" +cargo run --quiet --manifest-path "$ROOT_DIR/src-tauri/Cargo.toml" --bin stage_runner -- \ + --level-id "23_MinMaxFromStack" \ + --syntax Att \ + --asm "$STAGE_DIR/collect_Att.asm" +