Part01-01: Listing 38 with multiple mov instructions now working

This commit is contained in:
Joseph Ferano 2024-01-13 15:51:51 +07:00
parent 6ad9f66bc7
commit 6066e930db
3 changed files with 29 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/decode /decode
/.idea/ /.idea/
/asm_files/*.bin

17
asm_files/01-01-38.asm Normal file
View File

@ -0,0 +1,17 @@
; ========================================================================
; 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

View File

@ -60,11 +60,11 @@ int main(int argc, char **argv)
printf("; Decoded 8086 Assembly Instructions\n\n"); printf("; Decoded 8086 Assembly Instructions\n\n");
printf("bits 16\n\n"); printf("bits 16\n\n");
for (int i = 0; i < (int)bytes_read / 2; i += 2) for (int i = 0; i < (int)bytes_read; i += 2)
{ {
char low_byte = buf[i]; char low_byte = buf[i];
char high_byte = buf[i+1]; char high_byte = buf[i+1];
// char w = byte & 0b00000001; char w = low_byte & 0b00000001;
char d = low_byte & 0b00000010; char d = low_byte & 0b00000010;
char mod = (high_byte & 0b11000000) >> 6; char mod = (high_byte & 0b11000000) >> 6;
char reg = (high_byte & 0b00111000) >> 3; char reg = (high_byte & 0b00111000) >> 3;
@ -77,13 +77,20 @@ int main(int argc, char **argv)
{ {
case INST_MOV: case INST_MOV:
if (mod == MODE_REGMODE) if (mod == MODE_REGMODE)
{
if (w == 1)
{ {
printf("mov %s, %s", dst_reg.fullname, src_reg.fullname); printf("mov %s, %s", dst_reg.fullname, src_reg.fullname);
} }
else
{
printf("mov %s, %s", dst_reg.bytename, src_reg.bytename);
}
}
break; break;
default: default:
perror("Unrecognized Instruction\n"); perror("Unrecognized Instruction\n");
} }
}
printf("\n"); printf("\n");
} }
}