0% found this document useful (0 votes)
21 views16 pages

Memory Reference & I/O Instructions

Uploaded by

2024sl70006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views16 pages

Memory Reference & I/O Instructions

Uploaded by

2024sl70006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. /*W.A.

P to Create the machine for Memory Reference Instructions with addressing mode I=0
(AND,ADD,LDA) */
#include<stdio.h>
#include<conio.h>
int program[]={0x1064, 0x21C8, 0x38F2};
int choice=0;
int fetch()
{
printf("\nEnter your choice");
printf("\n1 for AND");
printf("\n2 for ADD");
printf("\n3 for LDA");
printf("\nEnter your choice: ");
scanf("%d", &choice);
return program[--choice];
}
int instrnum=0;
int acc=0xA937;
int mar= 0;
int instr1=0;
void decode(int instr)
{
instr1=instr;
instrnum= (instr1&0xF000)>>12;
switch(instrnum)
{
case 0: printf("\nADD");
mar=(instr & 0xFFF);
acc=acc&mar;
printf("\n%x", acc);
break;
case 1: printf("\nADD");
mar= (instr&0xFFF);
acc=acc+mar;
printf("\n%x", acc);
break;
case 2: printf("\nLDA");
mar=(instr&0xFFF);
acc=mar;
printf("\n%x", acc);
break;
}
}
void run()
{
int instr= fetch();
printf("\nProgram for direct addressing, I=0");

printf("\nInstr is %x", instr);


decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

2. /* W A P to Create the machine for Memory Reference Instructions with addressing mode I=0
(STA,BUN,BSA,ISZ) */
#include<stdio.h>
#include<conio.h>
void main()
{
int instr=0,acc=0xA937,DR=0,AR=0,instrnum;
int instr1,mar,PC;
clrscr();
printf("\nprogram for direct addressing, I=0");
printf("\nEnter 4xxx for STA");
printf("\nEnter 5xxx for BUN");
printf("\nEnter 6xxx for BSA");
printf("\nEnter 7xxx for ISZ ");
scanf("%x",&instr);
instr1=instr;
mar=(instr&0xFFF);
instrnum=(instr1 & 0xF000)>>12;
printf("THE instruction is %x",instrnum);
switch(instrnum)
{
case 4: printf("\n Store Accumulator(STA)");
mar=acc;
printf("\n Mar=%x",mar);
break;
case 5: printf("\n Branch Unconditionally(BUN)");
PC=AR;
break;
case 6: printf("\n Branch and Save Return Address(BSA)");
mar=PC;
PC=AR+1;
break;
case 7: printf("\n Increment and skip if zero(ISZ)");
DR=mar;
if(DR==0)
{
int PC=0x0022;
PC=PC+1;
}
else
DR=DR+1;
mar=DR;
printf("\n Now DR is %x",DR);
printf("\n Mar=%x",mar);
break;
}
getch();
}

3. /*W A P to Create the machine for Memory Reference Instructions


with addressing mode I=1 (AND,ADD,LDA) */
#include<stdio.h>
#include<conio.h>
int program[]={0x8064,0x91C8,0xA8F2};
int choice=0;
int fetch()
{
printf("\nEnter your choice ");
printf("\n0 for AND");
printf("\n1 for ADD");
printf("\n2 for LDA");
printf("\nEnter your choice ");
scanf("%d",&choice);
return program[choice];
}
int instrnum=0;
int dr=0;
int mar=0;
int acc=0xA937;
int operand[]={0x78A9,0xBE24,0x4DCA};
int instr1=0,ar;
void decode(int instr)
{
instr1=instr;
instrnum=(instr1&0xF000)>>12;
switch(instrnum)
{
case 8:printf("\nADD");
ar=(instr&0xFFFF);
mar=operand[0];
printf("\nOperand at address %x is %x",ar,mar);
dr=mar;
acc=acc&dr;
printf("\n%x",acc);
break;
case 9: printf("\nADD");
ar=(instr&0xFFF);
mar=operand[1];
printf("\nOperand at address %x is %x",ar,mar);
dr=mar;
acc=acc+dr;
printf("\n%x",acc);
break;
case 10:printf("\nLDA");
ar=(instr&0xFFF);
mar=operand[2];
printf("\noperand at address %x is %x",ar,mar);
dr=mar;
acc=dr;
printf("\n%x",acc);
}
}
void run()
{
int instr=fetch();
printf("\nProgram for Indirect addressing ,I=1");

printf("\nInstr is %x",instr);
decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

4. /*W A P to Create the machine for Memory Reference Instructions


with addressing mode I=1 (STA,BUN,BSA,ISZ) */
#include<stdio.h>
#include<conio.h>
void main()
{
int operand[]={0x78A9, 0xBE24, 0x4DCA, 0x56C7};
int acc=0xA937;
int dr=0;
int ar=0;
int pc=0x222;
int instr1;

int instr=0, instrnum, mar;


instr1=instr;
clrscr();
printf("\nProgram for indirect addressing I=1");
printf("\nEnter Bxxx for STA");
printf("\nEnter Cxxx for BUN");
printf("\nEnter Dxxx for BSA");
printf("\nEnter Exxx for ISZ ");

scanf("%x", &instr);
ar=(instr1&0xF000)>>12;
printf("The instruction is %x", instrnum);
switch(instrnum)
{
case 11: printf("\nStore Accumulator(STA)");
ar=(instr&0xFFF);
mar=acc;
printf("\nMar=", mar);
break;
case 12: printf("\Branch Unconditionally(BUN)");
ar=(instr&0xFFF);
mar=operand[1];
mar=pc;
pc=ar+1;
break;
case 13: printf("\nBranch and Save Return Address(BSA)");
ar=(instr&0xFFF);
mar=operand[2];
mar=pc;
pc=ar+1;
break;
case 14: printf("\nIncreament and skip if zero(ISZ)");
ar=(instr&0xFFF);
mar=operand[2];
dr=mar;
if(dr==0)
{
pc=pc+1;
}
else
dr=dr+1;
mar=dr;
printf("\Now DR is %x", dr);
printf("\nMar=%x", mar);
break;
}
getch();
}

5. /*W A P to Create the machine for Register Reference Instructions


(CLA,CMA,CLE,CME,CIR,CIL,INC) */
#include<stdio.h>
#include<conio.h>
int program[]={0x7800, 0x7400, 0x7200, 0x7100, 0x7080, 0x7040, 0x7020};
int choice=0;
int acc=0xA937;
int mar=0;
int instr1=0;
int E=0x0001;
int fetch()
{
printf("\n Enter ur choice");
printf("\n 1 for CLA");
printf("\n 2 for CLE");
printf("\n 3 for CMA");
printf("\n 4 for CME");
printf("\n 5 for CIR");
printf("\n 6 for CIL");
printf("\n 7 for INC ");
scanf("%d", &choice);
return program[--choice];
}
void decode(int instr)
{
int rem=0,bin=0,dci,cpy,base=1;
instr1=instr;
printf("\ninstr1 is %x ",instr);
mar=(instr1 & 0x0FFF);
printf("\nmar is %x ",mar);

cpy=mar;
while(cpy>0)
{
rem=cpy%16;
bin=bin+rem*base;
cpy=cpy/16;
base=base*10;
}
printf("\nhexadecimal value of mar is %x",bin);
switch(bin)
{
case 800:
{
printf("\n (CLA) Clear Accumulator ");
acc=0;
printf("\n The accumulator has been cleared and has becomne %x ", acc);
}
break;
case 400:
{ printf("\n (CLE) Clear E ");
E=0;
printf("\n The E has been cleared and has become %x ", E);
}
break;
case 200:
{ printf("\n (CMA) Complement Accumulator ");
acc=~acc;
printf("\n The complemented value of accumulator is %x ", acc);
}
break;
case 100:
{ printf("\n (CME) Complement E ");
E=~E;
printf("\n The complemented value of accumulator is %x ", E);
}
break;
case 80:
{ printf("\n (CIR) Circulate right ");
acc=acc>>1;
E=acc & 0x0001;
printf("\n The value of accumulator after circulate right is %x ", acc);
printf("\n The value of E ie. ACC(0) after circulate right is %x ", E);
}
break;
case 40:
{ printf("\n (CIL) Circulate left ");
acc=acc<<1;
E=acc & 0x8000;
printf("\n The value of accumulator after circulate is %x ", acc);
printf("\n The value of E ie. ACC(15) after circulate is %x ", E);
}
break;
case 20:
{ printf("\n (INC) increment AC ");
acc=acc+1;
printf("\n The value of after increment is %x " , acc);
}
break;
}
}
void run()
{
int instr=fetch();
printf("\n Progream to create machine for\n the register reference instructions\n CLA, CLE,
CMA, CIR, CIL and INC ");
printf("\n Instr is %x ", instr);
decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

6. /*Program to create machine for the register reference instruction


SPA,SNA,SZA,SZE,HLT */
#include<stdio.h>
#include<conio.h>
#include<process.h>
int program[]={0x7010, 0x7008, 0x7004, 0x7002, 0x7001};
int choice=0;
int fetch()
{
printf("\n Enter ur choice");
printf("\n 1 for SPA");
printf("\n 2 for SNA");
printf("\n 3 for SZA");
printf("\n 4 for SZE");
printf("\n 5 for HLT ");
scanf("%d", &choice);
return program[--choice];
}
int acc=0xA937;
int ac=(acc&0x8000)>>15;
int mar=0x000;
int pc=0x022;
int instr1=0;
int E=0x0001;
void decode(int instr)
{
instr1=instr;
mar=(instr1 & 0x0FFF);
switch(mar)
{
case 0x010:
printf("\n (SPA) Skip if positive ");
if(ac==0)
pc=pc+1;
printf("\n The content of pc is %x ", pc);
break;
case 0x008:
printf("\n (SNA) Skip if negative ");
if(ac==1)
pc=pc+1;
printf("\n The new content of pc is %x ", pc);
break;
case 0x004:
printf("\n (SZA) Skip if ACC is zero ");
if(acc==0)
pc=pc+1;
printf("\n The new content of pc is %x ", pc);
break;
case 0x002:
printf("\n (SZE) Skip if E is zero ");
if(E==0)
pc=pc+1;
printf("\n The new content of pc is %x ", pc);
break;
case 0x001:
printf("\n (HLT) Halt ");
exit(1);
break;
}
}
void run()
{
printf("\n Progream to create machine for\n the register reference instructions\n");
int instr=fetch();
printf("\n Instr is %x ", instr);
decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

7.

/*W A P to Create the machine for Input-Output Instructions


*/
#include<stdio.h>
#include<conio.h>
int choice=0;
int fetch()
{
printf("\n Enter ur choice");
printf("\n 1 for INP");
printf("\n 2 for OUT");
printf("\n 3 for SKI");
printf("\n 4 for SKO");
printf("\n 5 for ION");
printf("\n 6 for IOF ");
scanf("%d", &choice);
return choice;
}
int acc=0xA937;
int INPR=0xB8F2;
int PC=0x022;
int FGI=1;
int FGO=1;
int OUTR=0;
int IEN=0;
void decode(int instrcode)
{
switch(instrcode)
{
case 1:
printf("\n (INP) Input character ");
if(FGI==1)
{
acc=INPR;
FGI=0;
}
printf("\n The new content of accumulator will be %x",acc);
break;
case 2:
printf("\n (OUT) Output character ");
if(FGO==1)
{
OUTR=acc;
FGO=0;
}
printf("\n The new content of output register(OUTR)will be %x",OUTR);
break;
case 3:
printf("\n(SKI) Skip on Input flag ");
if(FGI==1)
{
PC=PC+1;
}
printf("\nThe new value of PC will be %x",PC);
break;
case 4:
printf("\n(SKO) Skip on Output Flag ");
if(FGO==1)
{
PC=PC+1;
}
printf("\nThe new value of PC will be %x ",PC);
break;
case 5:
printf("\n(ION) Interrupt On");
IEN=1;
printf("\nThe value of Interrupt now is ON an the value of IEN is %d ",IEN);
break;
case 6:
printf("\n(IOF) Interrupt Off ");
IEN=0;
printf("\nThe value of Interrupt now is OFF and value of IEN is %d",IEN);
break;
}
}
void run()
{
int instrcode=fetch();
printf("\n Progream to create machine for\n the input output instructions\n OUT,SKI,SKO,ION,
and IOF ");
decode(instrcode);
}
void main()
{
clrscr();
run();
getch();
}

8. /*W A P to Create the machine for Register Reference Instructions


(CLA,CMA,CLE,CME,CIR,CIL,INC) */
#include<conio.h>
#include<stdio.h>
int program[]={0x7800,0x7400,0x7200,0x7100,0x7080,0x7040,0x7020};
int choice=0;
int fetch()
{
printf("\nEnter your choice");
printf("\n1 for CLA");
printf("\n2 for CLE");
printf("\n3 for CMA");
printf("\n4 for CME");
printf("\n5 for CIR");
printf("\n6 for CIL");
printf("\n7 for INC");
printf("\nEnter your choice ");
scanf("%d",&choice);
return program[--choice];
}
int acc=0xA937;
int mar=0x0000;
int instr1=0;
int E=0x0001;
int PC=0x022;
void decode(int instr)
{
instr1=instr;
mar=(instr1 & 0x0FFF);
switch(mar)
{
case 0x800 : printf("\n (CLA) Clear Accumulator");
acc=0;
printf("\n The accumulator has been cleared and has become %x",acc);
break;
case 0x400 : printf("\n (CLE) Clear E");
E=0;
printf("\n The E has been cleared and has become %x",E);
break;
case 0x200 : printf("\n (CMA) Complement Accumulator");
acc=~acc;
printf("\n The complemented value of accumulator is %x",acc);
break;
case 0x100 : printf("\n (CME) Complement E");
E=~E;
printf("\n The compiemented value of E is %x",E);
break;
case 0x80 : printf("\n (CIR) Circulate right");
E=acc & 0x0001;
printf("\n The value of accumulator after circulate right is %x",acc);
printf("\nThe value of E ie. ACC(0) after circulate right is %x",E);
break;
case 0x40 : printf("\n (CIL) Circulate left");
acc=acc<<1;
E=acc & 0x8000;
printf("\n The value of accumulator after circulate left is %x",acc);
printf("\n The value of E ie. ACC(15) after circulate left is %x",E);
break;
case 0x20 : printf("\n (INC) Increment AC");
acc=acc+1;
printf("\n The value of accumulator after increment is %x",acc);
break;
}
}
void run()
{
int instr=fetch();
printf("\n program to simulate the machine to determine the contents");

printf("\n Instr is %x",instr);


decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

9. /*program to simulate a machine for the register reference instructions


SPA,SNA,SZA,SZE,HLT */
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
int program[]={0x7010,0x7008,0x7004,0x7002,0x7001};
int choice=0;
int fetch()
{
printf("\nEnter your choice");
printf("\n1 for SPA");
printf("\n2 for SNA");
printf("\n3 for SZA");
printf("\n4 for SZE");
printf("\n5 for HLT");
printf("\nEnter your choice ");
scanf("%d",&choice);
return program[--choice];
}
int acc=0xA937;
int ac=(acc & 0x8000)>>15;
int mar=0x0000;
int instr1=0;
int E=0x0001;
int pc=0x022;
void decode(int instr)
{
instr1=instr;
mar=(instr1 & 0x0FFF);
switch(mar)
{
case 0x010 : printf("\n (SPA) Skip if positive");
if(acc==0)
{
pc=pc+1;
}
printf("\n The new content of pc is %x",pc);
break;
case 0x008 : printf("\n (SNA) Skip if negative");
if(acc==1)
{
pc=pc+1;
}
printf("\n The new content of pc is %x",pc);
break;
case 0x004 : printf("\n (SZA) Skip if ACC is zero");
if(acc==0)
{
pc=pc+1;
}
printf("\n The new content of pc is %x",pc);
break;
case 0x100 : printf("\n (SZE) Skip if E is zero");
if(E==0)
{
pc=pc+1;
}
printf("\n The new content of pc is %x",pc);
break;
case 0x001 : printf("\n (HLT) Halt");
exit(0);
}
}
void run()
{
printf("\n program to simulate a machine for the register reference instructions
SPA,SNA,SZA,SZE and HLT");
int instr=fetch();
printf("\n Instr is %x",instr);
decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

10. /*W A P to Create the machine for Memory Reference Instructions


with I=0 at 022 in RAM,AC with A937 */
#include<stdio.h>
#include<conio.h>
int program[]={0x1064, 0x21C8, 0x38F2,0x4C34,0x567D,0x6E32,0x7B6A};
int choice=0,PC,AR=0,DR=0;
int instrnum=0;
int acc=0xA937;
int mar= 0;
int instr1=0;

int fetch()
{
printf("\nEnter your choice");
printf("\n1 for AND");
printf("\n2 for ADD");
printf("\n3 for LDA");
printf("\n4 for STA");
printf("\n5 for BUN");
printf("\n6 for BSA");
printf("\n7 for ISZ ");
printf("\nEnter your choice ");
scanf("%d", &choice);
return program[--choice];
}
void decode(int instr)
{
instr1=instr;
instrnum= (instr1&0xF000)>>12;
switch(instrnum)
{
case 1: printf("\nADD");
mar=(instr & 0xFFF);
acc=acc&mar;
printf("\n%x", acc);
break;
case 2: printf("\nADD");
mar= (instr&0xFFF);
acc=acc+mar;
printf("\n%x", acc);
break;
case 3: printf("\nLDA");
mar=(instr&0xFFF);
acc=mar;
printf("\n%x", acc);
break;
case 4: printf("\n Store Accumulator(STA)");
mar=acc;
printf("\n Mar=%x",mar);
break;
case 5: printf("\n Branch Unconditionally(BUN)");
PC=AR;
printf("\nNow PC is %x ",PC);
printf("\nNow AR is %x ",AR);
break;
case 6: printf("\n Branch and Save Return Address(BSA)");
mar=PC;
printf("\nNow AR is %x ",AR);
PC=AR+1;
printf("\nNow PC is %x ",PC);
break;
case 7: printf("\n Increment and skip if zero(ISZ)");
DR=mar;
if(DR==0)
PC=PC+1;
else
DR=DR+1;
mar=DR;
printf("\n Now DR is %x",DR);
printf("\n Mar=%x",mar);
break;
}
}
void run()
{
int instr= fetch();
printf("\nProgram for direct addressing, I=0");

printf("\nInstr is %x", instr);


printf("\nnow checking the instruction for opcode type ");
decode(instr);
}
void main()
{
clrscr();
run();
getch();
}

You might also like