Compare commits
No commits in common. "5fac2ebfa8745076ae7a78f4912070a7dc58338e" and "948eef0b4a30d64325c9ac341d5bd26d30fac463" have entirely different histories.
5fac2ebfa8
...
948eef0b4a
3
8086_assembly_01/.gitignore
vendored
3
8086_assembly_01/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
dasm
|
|
||||||
listing_0037_single_register_mov
|
|
||||||
listing_0038_many_register_mov
|
|
@ -1,2 +0,0 @@
|
|||||||
all:
|
|
||||||
clang++ -g dasm.cpp -o dasm
|
|
@ -1,159 +0,0 @@
|
|||||||
#include <bits/types/FILE.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// Bit patterns for the 8086 OPCODES
|
|
||||||
enum class OPCODES {
|
|
||||||
MOV = 0x88,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class OPMASKS {
|
|
||||||
MOV = 0xfc,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class FLAGS {
|
|
||||||
WORD = 0x01,
|
|
||||||
REG_DEST = 0x02,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class MODE {
|
|
||||||
MEM = 0x00,
|
|
||||||
MEM8 = 0x40,
|
|
||||||
MEM16 = 0x80,
|
|
||||||
REG = 0xc0,
|
|
||||||
};
|
|
||||||
|
|
||||||
uint16_t decode_mode(uint16_t instruction);
|
|
||||||
void decode_register(uint16_t instruction, bool word, char *dest);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
if (argc < 2) {
|
|
||||||
printf("Please provide a file to disassemble\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *filename = argv[1];
|
|
||||||
|
|
||||||
FILE *fp = fopen(filename, "rb");
|
|
||||||
|
|
||||||
if (fp) {
|
|
||||||
uint16_t inst = 0;
|
|
||||||
const char *op = "";
|
|
||||||
|
|
||||||
char out_filename[4096] = {0};
|
|
||||||
sprintf(out_filename, "%s_out.asm", filename);
|
|
||||||
|
|
||||||
FILE *out = fopen(out_filename, "w");
|
|
||||||
|
|
||||||
if (out) {
|
|
||||||
fprintf(out, "; Disassembled by DASM\n\nbits 16\n\n");
|
|
||||||
|
|
||||||
while (fread(&inst, sizeof(inst), 1, fp)) {
|
|
||||||
if ((inst & (uint16_t)OPMASKS::MOV) == (uint16_t)OPCODES::MOV) {
|
|
||||||
op = "mov";
|
|
||||||
|
|
||||||
bool reg_dest =
|
|
||||||
(inst & (uint16_t)FLAGS::REG_DEST) == (uint16_t)FLAGS::REG_DEST;
|
|
||||||
bool word = (inst & (uint16_t)FLAGS::WORD) == (uint16_t)FLAGS::WORD;
|
|
||||||
|
|
||||||
// NOTE: Using right shift will only work on little-endian CPUs
|
|
||||||
uint16_t operands_info = inst >> 8;
|
|
||||||
|
|
||||||
if (decode_mode(operands_info) == (uint16_t)MODE::REG) {
|
|
||||||
char rm[3] = {0};
|
|
||||||
char reg[3] = {0};
|
|
||||||
|
|
||||||
decode_register(operands_info, word, rm);
|
|
||||||
decode_register(operands_info >> 3, word, reg);
|
|
||||||
|
|
||||||
fprintf(out, "%s %s, %s\n", op, reg_dest ? reg : rm,
|
|
||||||
reg_dest ? rm : reg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("It's not a mov operation\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(out);
|
|
||||||
} else {
|
|
||||||
printf("Failed to open output file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
} else {
|
|
||||||
printf("Failed to open the selected file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t decode_mode(uint16_t instruction) {
|
|
||||||
uint16_t mode_mask = 0xc0;
|
|
||||||
|
|
||||||
return instruction & mode_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
void decode_register(uint16_t instruction, bool word, char *dest) {
|
|
||||||
uint16_t reg_mask = 0x07;
|
|
||||||
|
|
||||||
switch (instruction & reg_mask) {
|
|
||||||
case 0x00:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "ax");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "al");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x01:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "cx");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "cl");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x02:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "dx");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "dl");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x03:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "bx");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "bl");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x04:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "sp");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "ah");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x05:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "bp");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "ch");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x06:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "si");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "dh");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x07:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "di");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "bh");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ======================================================================== */
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 37
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
@ -1,5 +0,0 @@
|
|||||||
; Disassembled by DASM
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
@ -1,29 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ======================================================================== */
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 38
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
||||||
mov ch, ah
|
|
||||||
mov dx, bx
|
|
||||||
mov si, bx
|
|
||||||
mov bx, di
|
|
||||||
mov al, cl
|
|
||||||
mov ch, ch
|
|
||||||
mov bx, ax
|
|
||||||
mov bx, si
|
|
||||||
mov sp, di
|
|
||||||
mov bp, ax
|
|
@ -1,15 +0,0 @@
|
|||||||
; Disassembled by DASM
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
||||||
mov ch, ah
|
|
||||||
mov dx, bx
|
|
||||||
mov si, bx
|
|
||||||
mov bx, di
|
|
||||||
mov al, cl
|
|
||||||
mov ch, ch
|
|
||||||
mov bx, ax
|
|
||||||
mov bx, si
|
|
||||||
mov sp, di
|
|
||||||
mov bp, ax
|
|
20
Makefile
Normal file
20
Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
mk_haversine_fscanf:
|
||||||
|
clang++ -g haversine/cpp/fscanf.cpp haversine/cpp/haversine.cpp -o haversine/cpp/haverscan
|
||||||
|
|
||||||
|
run_haversine_fscanf:
|
||||||
|
cd ./haversine/cpp && ./haverscan
|
||||||
|
|
||||||
|
mk_haversine_strtok:
|
||||||
|
clang++ -g haversine/cpp/strtok.cpp haversine/cpp/haversine.cpp -o haversine/cpp/haverstrtok
|
||||||
|
|
||||||
|
run_haversine_strtok:
|
||||||
|
cd ./haversine/cpp && ./haverstrtok
|
||||||
|
|
||||||
|
mk_test:
|
||||||
|
clang++ -g -lpthread haversine/cpp/test.cpp haversine/cpp/haversine.cpp -o haversine/cpp/test
|
||||||
|
|
||||||
|
run_test:
|
||||||
|
cd ./haversine/cpp && ./test
|
||||||
|
|
||||||
|
run_haversine_python_json:
|
||||||
|
python ./haversine/python/haversine_json.py
|
@ -1,20 +0,0 @@
|
|||||||
mk_haversine_fscanf:
|
|
||||||
clang++ -g cpp/fscanf.cpp cpp/haversine.cpp -o cpp/haverscan
|
|
||||||
|
|
||||||
run_haversine_fscanf:
|
|
||||||
cd ./cpp && ./haverscan
|
|
||||||
|
|
||||||
mk_haversine_strtok:
|
|
||||||
clang++ -g cpp/strtok.cpp cpp/haversine.cpp -o cpp/haverstrtok
|
|
||||||
|
|
||||||
run_haversine_strtok:
|
|
||||||
cd ./cpp && ./haverstrtok
|
|
||||||
|
|
||||||
mk_test:
|
|
||||||
clang++ -g -lpthread cpp/test.cpp cpp/haversine.cpp -o cpp/test
|
|
||||||
|
|
||||||
run_test:
|
|
||||||
cd ./cpp && ./test
|
|
||||||
|
|
||||||
run_haversine_python_json:
|
|
||||||
python ./python/haversine_json.py
|
|
Loading…
Reference in New Issue
Block a user