From 3d29edbfc8b6845263b80ee61b195e658116e517 Mon Sep 17 00:00:00 2001 From: doyle Date: Fri, 31 Mar 2023 00:53:01 +1100 Subject: [PATCH] perfaware/part1: Support listing 0044 --- part1/build.bat | 85 +++++++++++++++------------ part1/listing_0044_register_movs | Bin 0 -> 28 bytes part1/listing_0044_register_movs.asm | 32 ++++++++++ part1/listing_0044_register_movs.txt | 24 ++++++++ part1/sim8086.c | 15 ++++- 5 files changed, 119 insertions(+), 37 deletions(-) create mode 100644 part1/listing_0044_register_movs create mode 100644 part1/listing_0044_register_movs.asm create mode 100644 part1/listing_0044_register_movs.txt diff --git a/part1/build.bat b/part1/build.bat index 777d145..d74f8dc 100644 --- a/part1/build.bat +++ b/part1/build.bat @@ -7,15 +7,6 @@ set script_dir=%script_dir_backslash:~0,-1% set build_dir=%script_dir%\build if not exist %build_dir% mkdir %build_dir% -copy /Y %script_dir%\listing_0037_single_register_mov %build_dir% 1>NUL -copy /Y %script_dir%\listing_0038_many_register_mov %build_dir% 1>NUL -copy /Y %script_dir%\listing_0039_more_movs %build_dir% 1>NUL -copy /Y %script_dir%\listing_0040_challenge_movs %build_dir% 1>NUL -copy /Y %script_dir%\listing_0041_add_sub_cmp_jnz %build_dir% 1>NUL -copy /Y %script_dir%\listing_0042_completionist_decode %build_dir% 1>NUL -copy /Y %script_dir%\listing_0043_immediate_movs %build_dir% 1>NUL -copy /Y %script_dir%\listing_0043_immediate_movs.txt %build_dir% 1>NUL - REM Build REM =========================================================================== pushd %build_dir% @@ -24,36 +15,58 @@ popd REM Tests REM =========================================================================== -set listing_0037=%build_dir%\listing_0037_single_register_mov -%build_dir%\sim8086.exe %listing_0037% > %listing_0037%_disassembled.asm -nasm %listing_0037%_disassembled.asm -fc /B %listing_0037% %listing_0037%_disassembled || exit /b 1 +set listing_0037=listing_0037_single_register_mov +copy /Y %script_dir%\%listing_0037% %build_dir% 1>NUL +set build_dir_listing_0037=%build_dir%\%listing_0037% +%build_dir%\sim8086.exe %build_dir_listing_0037% > %build_dir_listing_0037%_disassembled.asm +nasm %build_dir_listing_0037%_disassembled.asm +fc /B %build_dir_listing_0037% %build_dir_listing_0037%_disassembled || exit /b 1 -set listing_0038=%build_dir%\listing_0038_many_register_mov -%build_dir%\sim8086.exe %listing_0038% > %listing_0038%_disassembled.asm -nasm %listing_0038%_disassembled.asm -fc /B %listing_0038% %listing_0038%_disassembled || exit /b 1 +set listing_0038=listing_0038_many_register_mov +copy /Y %script_dir%\%listing_0038% %build_dir% 1>NUL +set build_dir_listing_0038=%build_dir%\%listing_0038% +%build_dir%\sim8086.exe %build_dir_listing_0038% > %build_dir_listing_0038%_disassembled.asm +nasm %build_dir_listing_0038%_disassembled.asm +fc /B %build_dir_listing_0038% %build_dir_listing_0038%_disassembled || exit /b 1 -set listing_0039=%build_dir%\listing_0039_more_movs -%build_dir%\sim8086.exe %listing_0039% > %listing_0039%_disassembled.asm -nasm %listing_0039%_disassembled.asm -fc /B %listing_0039% %listing_0039%_disassembled || exit /b 1 +set listing_0039=listing_0039_more_movs +copy /Y %script_dir%\%listing_0039% %build_dir% 1>NUL +set build_dir_listing_0039=%build_dir%\%listing_0039% +%build_dir%\sim8086.exe %build_dir_listing_0039% > %build_dir_listing_0039%_disassembled.asm +nasm %build_dir_listing_0039%_disassembled.asm +fc /B %build_dir_listing_0039% %build_dir_listing_0039%_disassembled || exit /b 1 -set listing_0040=%build_dir%\listing_0040_challenge_movs -%build_dir%\sim8086.exe %listing_0040% > %listing_0040%_disassembled.asm -nasm %listing_0040%_disassembled.asm -fc /B %listing_0040% %listing_0040%_disassembled || exit /b 1 +set listing_0040=listing_0040_challenge_movs +copy /Y %script_dir%\%listing_0040% %build_dir% 1>NUL +set build_dir_listing_0040=%build_dir%\%listing_0040% +%build_dir%\sim8086.exe %build_dir_listing_0040% > %build_dir_listing_0040%_disassembled.asm +nasm %build_dir_listing_0040%_disassembled.asm +fc /B %build_dir_listing_0040% %build_dir_listing_0040%_disassembled || exit /b 1 -set listing_0041=%build_dir%\listing_0041_add_sub_cmp_jnz -%build_dir%\sim8086.exe %listing_0041% > %listing_0041%_disassembled.asm -nasm %listing_0041%_disassembled.asm -fc /B %listing_0041% %listing_0041%_disassembled || exit /b 1 +set listing_0041=listing_0041_add_sub_cmp_jnz +copy /Y %script_dir%\%listing_0041% %build_dir% 1>NUL +set build_dir_listing_0041=%build_dir%\%listing_0041% +%build_dir%\sim8086.exe %build_dir_listing_0041% > %build_dir_listing_0041%_disassembled.asm +nasm %build_dir_listing_0041%_disassembled.asm +fc /B %build_dir_listing_0041% %build_dir_listing_0041%_disassembled || exit /b 1 -set listing_0042=%build_dir%\listing_0042_completionist_decode -%build_dir%\sim8086.exe %listing_0042% > %listing_0042%_disassembled.asm -nasm %listing_0042%_disassembled.asm -fc /B %listing_0042% %listing_0042%_disassembled || exit /b 1 +set listing_0042=listing_0042_completionist_decode +copy /Y %script_dir%\%listing_0042% %build_dir% 1>NUL +set build_dir_listing_0042=%build_dir%\%listing_0042% +%build_dir%\sim8086.exe %build_dir_listing_0042% > %build_dir_listing_0042%_disassembled.asm +nasm %build_dir_listing_0042%_disassembled.asm +fc /B %build_dir_listing_0042% %build_dir_listing_0042%_disassembled || exit /b 1 -set listing_0043=%build_dir%\listing_0043_immediate_movs -%build_dir%\sim8086.exe --exec %listing_0043% > %listing_0043%_disassembled.txt -fc /N %listing_0043%.txt %listing_0043%_disassembled.txt || exit /b 1 +set listing_0043=listing_0043_immediate_movs +copy /Y %script_dir%\%listing_0043% %build_dir% 1>NUL +copy /Y %script_dir%\%listing_0043%.txt %build_dir% 1>NUL +set build_dir_listing_0043=%build_dir%\%listing_0043% +%build_dir%\sim8086.exe --exec %build_dir_listing_0043% > %build_dir_listing_0043%_disassembled.txt +fc /N %build_dir_listing_0043%.txt %build_dir_listing_0043%_disassembled.txt || exit /b 1 + +set listing_0044=listing_0044_register_movs +copy /Y %script_dir%\%listing_0044% %build_dir% 1>NUL +copy /Y %script_dir%\%listing_0044%.txt %build_dir% 1>NUL +set build_dir_listing_0044=%build_dir%\%listing_0044% +%build_dir%\sim8086.exe --exec %build_dir_listing_0044% > %build_dir_listing_0044%_disassembled.txt +fc /N %build_dir_listing_0044%.txt %build_dir_listing_0044%_disassembled.txt || exit /b 1 diff --git a/part1/listing_0044_register_movs b/part1/listing_0044_register_movs new file mode 100644 index 0000000000000000000000000000000000000000..346ff45a6be863edf2dc166f4d91969223a74b73 GIT binary patch literal 28 kcmdnN$grD0x1 +mov bx, 2 ; bx:0x0->0x2 +mov cx, 3 ; cx:0x0->0x3 +mov dx, 4 ; dx:0x0->0x4 +mov sp, ax ; sp:0x0->0x1 +mov bp, bx ; bp:0x0->0x2 +mov si, cx ; si:0x0->0x3 +mov di, dx ; di:0x0->0x4 +mov dx, sp ; dx:0x4->0x1 +mov cx, bp ; cx:0x3->0x2 +mov bx, si ; bx:0x2->0x3 +mov ax, di ; ax:0x1->0x4 + +Final registers: + ax: 0x0004 (4) + bx: 0x0003 (3) + cx: 0x0002 (2) + dx: 0x0001 (1) + sp: 0x0001 (1) + bp: 0x0002 (2) + si: 0x0003 (3) + di: 0x0004 (4) + diff --git a/part1/sim8086.c b/part1/sim8086.c index 9b6534a..d6e5f33 100644 --- a/part1/sim8086.c +++ b/part1/sim8086.c @@ -1172,6 +1172,18 @@ int main(int argc, char **argv) S86_Str8 mnemonic_op = S86_MnemonicOpStr8(dest_map->mnemonic_op); S86_PrintFmt(" ; %.*s:0x%x->0x%x ", S86_STR8_FMT(mnemonic_op), *dest, opcode.immediate); *dest = (uint16_t)opcode.immediate; + } else if (opcode.src >= S86_MnemonicOp_AX && opcode.src <= S86_MnemonicOp_DI) { + MnemonicOpToRegisterFileMap const *src_map = NULL; + for (size_t index = 0; !src_map && index < S86_ARRAY_UCOUNT(mnemonic_op_to_register_file_map); index++) { + MnemonicOpToRegisterFileMap const *item = mnemonic_op_to_register_file_map + index; + if (item->mnemonic_op == opcode.src) + src_map = item; + } + + S86_Str8 dest_op = S86_MnemonicOpStr8(dest_map->mnemonic_op); + uint16_t *src = src_map->reg; + S86_PrintFmt(" ; %.*s:0x%x->0x%x ", S86_STR8_FMT(dest_op), *dest, *src); + *dest = *src; } } } @@ -1186,7 +1198,8 @@ int main(int argc, char **argv) S86_PrintLnFmt(" dx: 0x%04x (%u)", register_file.dx, register_file.dx); S86_PrintLnFmt(" sp: 0x%04x (%u)", register_file.sp, register_file.sp); S86_PrintLnFmt(" bp: 0x%04x (%u)", register_file.bp, register_file.bp); - S86_PrintLnFmt(" si: 0x%04x (%u)", register_file.si, register_file.si); S86_PrintLnFmt(" di: 0x%04x (%u)", register_file.di, register_file.di); + S86_PrintLnFmt(" si: 0x%04x (%u)", register_file.si, register_file.si); + S86_PrintLnFmt(" di: 0x%04x (%u)", register_file.di, register_file.di); S86_Print(S86_STR8("\n")); } }