1-2: Assignment complete w/o challenge
This commit is contained in:
parent
eb2c1cb0f9
commit
1a7041ab9d
6 changed files with 120 additions and 29 deletions
BIN
1-2/8086coded
BIN
1-2/8086coded
Binary file not shown.
100
1-2/decoder.c
100
1-2/decoder.c
|
|
@ -30,29 +30,29 @@ char REG_ENCODING_TXT[0b10000][REG_ENCODING_TXT_LEN] = { "al", "cl", "dl", "bl",
|
|||
char EA_ENCODING_TXT[0b1000][EA_ENCODING_TXT_LEN] = { "bx + si", "bx + di", "bp + si", "bp + di",
|
||||
"si", "di", "bp", "bx"};
|
||||
|
||||
enum REG_ENCODING
|
||||
{
|
||||
R_AL = 0b000,
|
||||
R_CL = 0b001,
|
||||
R_DL = 0b010,
|
||||
R_BL = 0b011,
|
||||
R_AH = 0b100,
|
||||
R_CH = 0b101,
|
||||
R_DH = 0b110,
|
||||
R_BH = 0b111
|
||||
};
|
||||
/* enum REG_ENCODING */
|
||||
/* { */
|
||||
/* R_AL = 0b000, */
|
||||
/* R_CL = 0b001, */
|
||||
/* R_DL = 0b010, */
|
||||
/* R_BL = 0b011, */
|
||||
/* R_AH = 0b100, */
|
||||
/* R_CH = 0b101, */
|
||||
/* R_DH = 0b110, */
|
||||
/* R_BH = 0b111 */
|
||||
/* }; */
|
||||
|
||||
enum WREG_ENCODING
|
||||
{
|
||||
WR_AX = 0b000,
|
||||
WR_CX = 0b001,
|
||||
WR_DX = 0b010,
|
||||
WR_BX = 0b011,
|
||||
WR_SP = 0b100,
|
||||
WR_BP = 0b101,
|
||||
WR_SI = 0b110,
|
||||
WR_DI = 0b111
|
||||
};
|
||||
/* enum WREG_ENCODING */
|
||||
/* { */
|
||||
/* WR_AX = 0b000, */
|
||||
/* WR_CX = 0b001, */
|
||||
/* WR_DX = 0b010, */
|
||||
/* WR_BX = 0b011, */
|
||||
/* WR_SP = 0b100, */
|
||||
/* WR_BP = 0b101, */
|
||||
/* WR_SI = 0b110, */
|
||||
/* WR_DI = 0b111 */
|
||||
/* }; */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
@ -63,6 +63,35 @@ typedef struct
|
|||
FILE *output;
|
||||
binary_data bin;
|
||||
|
||||
int MOV_I_T_R_parse(uint8_t byte1, uint8_t byte2, binary_data *binary, int bytes_read)
|
||||
{
|
||||
const uint8_t wide_mask = 0b0000'1000;
|
||||
const uint8_t reg_mask = 0b0000'0111;
|
||||
unsigned char byte[1];
|
||||
uint8_t extra_bytes_read = 0;
|
||||
uint16_t full_im = byte2;
|
||||
uint8_t high_im = 0;
|
||||
uint8_t reg_value = 0;
|
||||
|
||||
//Immediate value retrieval
|
||||
if (wide_mask & byte1)
|
||||
{
|
||||
fread(byte, sizeof(byte), 1, bin.binary);
|
||||
extra_bytes_read++;
|
||||
high_im = (uint8_t)byte[0];
|
||||
full_im = full_im + (high_im << 8);
|
||||
}
|
||||
|
||||
//target reg retrieval
|
||||
reg_value = (byte1 & reg_mask) + (((byte1 & wide_mask) >> 3) * 8);
|
||||
|
||||
printf("%s %s, %d\n", "mov", REG_ENCODING_TXT[reg_value], full_im);
|
||||
fprintf(output, "%s %s, %d\n", "mov", REG_ENCODING_TXT[reg_value], full_im);
|
||||
|
||||
return extra_bytes_read;
|
||||
}
|
||||
|
||||
|
||||
int MOV_RM_TF_R_parse(uint8_t byte1, uint8_t byte2, binary_data *binary, int bytes_read)
|
||||
{
|
||||
const uint8_t wide_mask = 0b0000'0001;
|
||||
|
|
@ -237,14 +266,27 @@ int main(int argc, char** argv)
|
|||
fread(byte, sizeof(byte), 1, bin.binary);
|
||||
uint8_t manip_inst = (uint8_t)byte[0];
|
||||
uint8_t inst = (uint8_t)byte[0];
|
||||
//For now we're just checking for RM_TF_R
|
||||
//We're checking for MOV RM_TF_R and MOV I_T_R
|
||||
manip_inst = (manip_inst >> 2);
|
||||
if (manip_inst != MOV_RM_TF_R) break;
|
||||
if (bytes_read >= bin.size) break;
|
||||
fread(byte, sizeof(byte), 1, bin.binary);
|
||||
bytes_read++;
|
||||
uint8_t inst_byte2 = (uint8_t)byte[0];
|
||||
bytes_read += MOV_RM_TF_R_parse(inst, inst_byte2, 0, 0);
|
||||
if (manip_inst == MOV_RM_TF_R)
|
||||
{
|
||||
if (bytes_read >= bin.size) break;
|
||||
fread(byte, sizeof(byte), 1, bin.binary);
|
||||
bytes_read++;
|
||||
uint8_t inst_byte2 = (uint8_t)byte[0];
|
||||
bytes_read += MOV_RM_TF_R_parse(inst, inst_byte2, 0, 0);
|
||||
continue;
|
||||
}
|
||||
manip_inst = (manip_inst >> 2);
|
||||
if (manip_inst == MOV_I_T_R)
|
||||
{
|
||||
if (bytes_read >= bin.size) break;
|
||||
fread(byte, sizeof(byte), 1, bin.binary);
|
||||
bytes_read++;
|
||||
uint8_t inst_byte2 = (uint8_t)byte[0];
|
||||
bytes_read += MOV_I_T_R_parse(inst, inst_byte2, 0, 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
BIN
1-2/listing-39
Normal file
BIN
1-2/listing-39
Normal file
Binary file not shown.
31
1-2/listing-39.asm
Normal file
31
1-2/listing-39.asm
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
bits 16
|
||||
|
||||
; Register-to-register
|
||||
mov si, bx
|
||||
mov dh, al
|
||||
|
||||
; 8-bit immediate-to-register
|
||||
mov cl, 12
|
||||
mov ch, -12
|
||||
|
||||
; 16-bit immediate-to-register
|
||||
mov cx, 12
|
||||
mov cx, -12
|
||||
mov dx, 3948
|
||||
mov dx, -3948
|
||||
|
||||
; Source address calculation
|
||||
mov al, [bx + si]
|
||||
mov bx, [bp + di]
|
||||
mov dx, [bp]
|
||||
|
||||
; Source address calculation plus 8-bit displacement
|
||||
mov ah, [bx + si + 4]
|
||||
|
||||
; Source address calculation plus 16-bit displacement
|
||||
mov al, [bx + si + 4999]
|
||||
|
||||
; Dest address calculation
|
||||
mov [bx + di], cx
|
||||
mov [bp + si], cl
|
||||
mov [bp], ch
|
||||
BIN
1-2/output
Normal file
BIN
1-2/output
Normal file
Binary file not shown.
18
1-2/output.asm
Normal file
18
1-2/output.asm
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
bits 16
|
||||
|
||||
mov si, bx
|
||||
mov dh, al
|
||||
mov cl, 12
|
||||
mov ch, 244
|
||||
mov cx, 12
|
||||
mov cx, 65524
|
||||
mov dx, 3948
|
||||
mov dx, 61588
|
||||
mov al, [bx + si]
|
||||
mov bx, [bp + di]
|
||||
mov dx, [bp + 0]
|
||||
mov ah, [bx + si + 4]
|
||||
mov al, [bx + si + 4999]
|
||||
mov [bx + di], cx
|
||||
mov [bp + si], cl
|
||||
mov [bp + 0], ch
|
||||
Loading…
Add table
Add a link
Reference in a new issue