Documente Academic
Documente Profesional
Documente Cultură
DATA SEGMENT
NUM1 DW 000AH
NUM2 DW 0004H
GCD DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX.
MOV DS,AX ;Move the Data AX to DS.
MOV AX,NUM1 ;Move the first number to AX.
MOV BX,NUM2 ;Move the second number to BX.
UP: CMP AX,BX ;Compare the two numbers.
JE EXIT ;If equal, go to EXIT label.
JB EXCG ;If first number is below than second,
;go to EXCG label.
UP1: MOV DX,0H ;Initialize the DX.
DIV BX ;Divide the first number by second number.
CMP DX,0 ;Compare remainder is zero or not.
JE EXIT ;If zero, jump to EXIT label.
MOV AX,DX ;If non-zero, move remainder to AX.
JMP UP ;Jump to UP label.
EXCG:XCHG AX,BX ;Exchange the remainder and quotient.
JMP UP1 ;Jump to UP1.
EXIT:MOV GCD,BX ;Store the result in GCD.
MOV AH,4CH
INT 21H
CODE ENDS
END START
Ourcode:
MVI AX 88 2
MVI BX 84 2
MOV AX, BX 82 1
STA Address 81 2
XCHG AX, BX 80 1
Arithematic:
SUB BX 48 1
Control:
CMP BX 2C 1
JE Label 28 2
JB Label 24 2
JMP Label 22 2
CZ Label 21 2
HLT 20 1
88 08 0000000010001000
0000000000001000
84 04 0000000010000100
0000000000000100
2C 0000000000101100
28 1220 0000000000101000
0001001000100000
24 0E20 0000000000100100
0000111000100000
48 0000000000101000
21 1220 0000000000100001
0001001000100000
22 0420 0000000000100010
0000010000100000
80 0000000001000000
22 0920 0000000000100010
0000100100100000
82 0000000010000010
81 0050 0000000010000001
0000000001010000
20 0000000000100000
Code:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
struct proc{
char byte[50];
};
struct reg{
char byte[50]; int set;
};
char memory[][16]={"01010100","00010101","00110110"};
char control[3][50]={"LOAD","ADD","STORE"}; //i dont think we need this control variable
char
register[][16]={"0000000000000000","0000000000000000","0000000000000000","0000000000000
000"};
int flags[2]={0};//flags[0]= 1 when equal flags[1]=1 when num1<num2;
int bytes[3]={1,2,3};
struct proc pc,mar,mdr,ir,temp;
struct reg ax, bx;
int to_b,cu_b,opcode_dec;
struct proc decToBinary(int n,int s)
{
int binaryNum[32];
int i = 0;
while (n > 0) {
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
while(i<s)
{
binaryNum[i]=0;i++;
}
int d=atoi(src.byte);
d=bintodec(d);
printf("%d\n",d);
d++;
src=decToBinary(d,8);
//printf("%s\n",src.byte);
return src;
}
void decode()
{
mdr=map(mar);
printf("\n%s\n",mdr.byte);
strcpy(ir.byte,mdr.byte);
}
case 22:
int first_byte = temp;
int second_byte = data_val();
register[0] = first_byte;
control(second_byte,temp);
break;
int main()
{
strcpy(pc.byte,"00000001");
while(1)
{
fetch();
cu_b=1; //current_byte
decode();
if(to_b > 1)
temp=data_val();
if(opcode_dec > 80 && !(opcode_dec == 824))//when 2C is converted to dec we get '824';
transfer(opcode_dec,temp);
else if(opcode_dec == 48)
arithmetic(opcode_dec);
else
control(opcode_dec,temp);
}
return 0;
}