[bits 32] %define stdin 0 %define stdout 1 %define stderr 2 ; call kernel %define kernel 0x80 ; system calls %define _exit 1 %define _fork 2 %define _read 3 %define _write 4 %define _execve 11 %define _chdir 12 %define _wait 114 %macro exit 1.nolist mov ebx, %1 mov eax, _exit int kernel %endmacro %macro read 2.nolist mov ebx, stdin mov ecx, %1 mov edx, %2 mov eax, _read int kernel %endmacro %macro write 2.nolist mov ebx, stdout mov ecx, %1 mov edx, %2 mov eax, _write int kernel %endmacro %macro fork 0.nolist mov eax, _fork int kernel %endmacro %macro exec 3.nolist mov ebx, %1 mov ecx, %2 mov edx, %3 mov eax, _execve int kernel %endmacro %macro chdir 1.nolist mov ebx, %1 mov eax, _chdir int kernel %endmacro %macro wait 1.nolist mov ebx, %1 mov ecx, 0 mov edx, 0 mov eax, _wait int kernel %endmacro [section .data] prompt: db "command: " .len equ $-prompt cnfmsg: db ": not found", 0xa .len equ $-cnfmsg uarg: db "unknown argument", 0xa .len equ $-uarg [section .bss] array: resw 32 buffer: resb 1024 cpuinfo: resb 13 len: resw 1 [section .text] [global _start] [global main] [global child] [global die] [global showcpu] die: exit 0 showcpu: xor eax, eax cpuid mov [cpuinfo], ebx mov [cpuinfo+4], edx mov [cpuinfo+8], ecx mov [cpuinfo+12], byte 0xa write cpuinfo, 13 jmp main _start: pop ebx cmp ebx, 1 jne .usage jmp main .usage: write uarg, uarg.len jmp die main: write prompt, prompt.len read buffer, 1024 cmp eax, 1 je main dec eax mov [buffer+eax], byte 0 cmp [buffer], dword "exit" je die cmp [buffer], dword "quit" je die cmp [buffer], dword "cpu" je showcpu ; mov ecx, 0 ; mov ebx, dword buffer ;.lead_space ; cmp [buffer+ecx], byte 0x20 ; jne .execute ; inc ecx ; inc ebx ; inc ebx ; inc ebx ; inc ebx ; jmp .lead_space ;.execute ; mov [buffer], dword ebx mov ebx, -1 mov ecx, 4 mov [len], dword 0 mov [array], dword buffer fork test eax, eax jz .parse_str wait 0 jmp main .parse_str: inc ebx cmp [buffer+ebx], byte 0x20 je .chk_arg1 cmp [buffer+ebx], byte 0 je .chk_arg2 jmp .parse_str .chk_arg1 cmp [len], dword 0 jne .add_array mov [len], ebx jmp .add_array .chk_arg2 cmp [len], dword 0 jne child mov [len], ebx jmp child .add_array: mov [buffer+ebx], byte 0 lea eax, [buffer+ebx+1] add [array+ecx], eax add ecx, 4 jmp .parse_str child: exec buffer, array, 0 test eax, eax js .cnf .cnf: write buffer, [len] write cnfmsg, cnfmsg.len exit 1