Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Lms lenguaje maquina simpletron

Estas en el tema de Lms lenguaje maquina simpletron en el foro de C/C++ en Foros del Web. Hola a todos, solo quiciera saber como poder hacer este ejercicio, solo necesito el codigo para compilarlo y ver que si funcione, ya despues de ...
  #1 (permalink)  
Antiguo 03/08/2010, 20:34
 
Fecha de Ingreso: agosto-2010
Mensajes: 153
Antigüedad: 13 años, 8 meses
Puntos: 1
Lms lenguaje maquina simpletron

Hola a todos, solo quiciera saber como poder hacer este ejercicio, solo necesito el codigo para compilarlo y ver que si funcione, ya despues de eso yo lo sigo intentando gracias


VAMOS A CREAR UNA COMPUTADORA A LA CUAL LLAMAREMOS SIMPLETRON. COMO SU NOMBRE LO INDICA, ES UNA MAQUINA SIMPLE, PERO COMO VEREMOS PRONTO, TAMBIEN ES PODEROSA. EL SIMPLETRON EJECUTA PROGRAMAS ESCRITRS EN EL UNICO LENGUAJE QUE COMPRENDE LA COMPUTADORA DE MANERA DIRECTA, ESTO ES EL LENGUAJE MAQUINA DE SIMPLETRON, LMS
EL SIMPLETRON CONTIENE UN ACUMULADOR, UN REGISTRO ESPECIAL EN EL CUAL LA INFORMACION SE COLOCA ANTES DE QUE EL SIMPLETRON UTILICE DICHA INFORMACION EN LOS CALCULOS O QUE LA EXAMINE DE DISTINTA MANERA. TODA LA INFORMACION EN EL SIMPLETRON SE MANEJA MEDIANTE PALABRAS. UNA PALABRA ES UN NUMERO DECIMAL DE CUATRO DIGITOS CON SIGNO, TAL COMO +3364, -1293, +0007, -0001, ETCETERA. EL SIMPLETRON ESTA EQUIPADO CON 100 PALABRAS DE MEMORIA Y SE HACE REFERENCIA A ESTAS PALABRAS MEDIANTE SU NUEMRO DE UBICACION 00, 01, ..., 99
ANTES DE EJECUTAR UN PROGRAMA LMS SIEMPRE SE COLOCA EN LA UBICACION 00
CADA INSTRUCCION ESCRITA EN LMS OCUPA UNA PALABRA EN LA MEMORIA DEL SIMPLETRON ( Y POR LO TANTO, LAS INSTRUCCIONES SON NUMEROS DECIMALES DE CUATRO DIGITOS ). ASUMIMOS QUE EL SIGNO DE UNA ISNTRUCCION LMS SIEMPRE ES POSITIVO, POR EL SIGNO DE UNA PALABRA DE DATOS PUEDE SER POSITIVO O NEGATIVO. CADA DIRECCION EN LA MEMORIA DEL SIMPLETRON PUEDE CONTENER UNA INSTRUCCION, UN VALOR DE DATO QUE EL PROGRAMA UTILIZA O UN AREA DE MEMORIA SIN UTILIZAR ( POR LO TANTO, INDEFINIDA ). LOS PRIMEROS DOS DIGITOS DE CADA INSTRUCCION LMS REPRESENTA EL CODIGO DE OPERACION, EL CUAL ESPECIFICA LA OPERACION A REALIZAR. RESUMIMOS LOS CODIGOS DE OPERACION DE LMS EN LA FIGURA 7.32

CODIGO DE OPERACION SIGNIFICADO
Operaciones de entrada/salida
#define LEE 10 LEE UNA PALABRA DESDE LA TERMINAL Y LA ALMACENA EN LA UBICACION DE MEMORIA
#define ESCRIBE 11 ESCRIBE UNA PALABRA DESDE UNA UBICACION ESPECIFICA DE MEMORIA HACIA LA TERMINAL

Operaciones de carga/almacenamiento
#define CARGA 20 CARGA UNA PALABRA DESDE LA UBICCION ESPECIFICA DE MEMORIA HACIA EL ACUMULADOR
#define ALMACENA 21 ALAMCENA UNA PALABRA DESDE EL ACUMULADOR HACIA UNA UBICACION ESPECIFICA DE MEMORIA

Operaciones aritmeticas
#define SUMA 30 SUMA UNA PALABRA DESDE UNA UBICACION ESPECIFICA DE MEMORIA A LA PALABRA ALMACENADA EN EL ACUMULADOR ( DEJA EL RESULTADO EN EL ACUMULADOR )
#define RESTA 31 RESTA UNA PALABRA DESDE UNA UBICACION ESPECIFICA DE MEMORIA DEL ACUMULADOR ( DEJA EL RESULTADO EN EL ACUMULADOR )
#define DIVIDE 32 DIVIDE UNA PALABRA DESDE UNA UBICACION ESPECIFICA DE MEMORIA ENTRE LA PALABRA DENTRO DEL ACUMULADOR ( DEJA EL RESULTADO EN EL ACUMULADOR )
#define MULTIPLICA 33 MULTIPLICA UNA PALABRA DESDE UNA UBICACION ESPECIFICA DE MEMORIA POR LA PALABRA ALAMCENADA DENTRO DEL ACUMULADOR ( DJEA EL RESULTADO EN EL ACUMULADOR )

Operaciones de transferencia de control:
#define SALTA 40 SALTA A UNA UBICACION ESPECIFICA DE MEMORIA
#define SALTANEG 41 SALTA HACIA UNA UBICACION ESPECIFICA DE MEMORIA SI EL ACUMULADOR ES NEGATIVO
#define SALTACERO 42 SALTA A UNA UBICACION ESPECIFICA DE MEMORIA SI EL ACUMULADOR ES IGUAL A CERO
#define ALTO 43 PARA, ES DECIR, EL PROGRAMA FINALIZO SU TAREA

FIGURA 7.32

LOS DOS ULTIMOS DIGITOS DE UNA INSTRUCCION LMS SON EL OPERANDO, EL CUAL ES LA DIRECCION DE LA UBICACION DE MEMORIA QUE CONTIENE LA PALABRA A LA CUAL SE APLICA LA OPERACION. AHORA, CONSIDEREMOS VARIOS EJEMPLOS DE PROGRAMAS LMS:

EJEMPLO 1
UBICACION NUMERO INSTRUCCION

00 +1007 LEE A
01 +1008 LEE B
02 +2007 CARGA A
03 +3008 SUMA B
04 +2109 ALMACENA C
05 +1109 ESCRIBA C
06 +4300 ALTO
07 +0000 VARIABLE A
08 +0000 VARIABLE B
09 +000 RESULTADO C
  #2 (permalink)  
Antiguo 03/08/2010, 20:41
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
Respuesta: Lms lenguaje maquina simpletron

No se de donde estas sacando ejercicio, pero podrias empezar con algo mas bascico. O un poco mas corto por lo menos. No es tan complicado hacer esto. Pero es medio tedioso y repetitivo y la verdad llevaria un poco de tiempo. Con algo mas corto creo que se podria aprender mas....

No interperte que no te queremos ayudar pero tampoco estoy tan al pedo como para leer todo entero el problema y hacerlo.
  #3 (permalink)  
Antiguo 03/08/2010, 20:46
 
Fecha de Ingreso: agosto-2010
Mensajes: 153
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Lms lenguaje maquina simpletron

ok disculpa por tanto rollo, solo necesito un pequeño programita LMS para poder estudiarlo yo mismo, son ejercicos de lecciones pasadas que no pude hacer, es que mas o menos le comprendo pero necesito uno hecho para poder ahora si confirmar como va todo acomodado, por que son puras instrucciones del preprocesador creo no????? gracias por tu ayuda, te agradeceria ese pequeñito programa, aunque sea uno que solo sume e imprima el resultado gracias
  #4 (permalink)  
Antiguo 19/11/2012, 07:20
Avatar de sofiarivas93  
Fecha de Ingreso: noviembre-2012
Mensajes: 1
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Lms lenguaje maquina simpletron

Aqui te dejo el codigo completo hecho en Ansi c espero que te ayude

//Computadora Simpletron
#include <stdio.h>
#include <stdlib.h>
#define LEE 10
#define ESCRIBE 11
#define CARGA 20
#define ALMACENA 21
#define SUMA 30
#define RESTA 31
#define DIVIDE 32
#define MULTIPLICA 33
#define SALTA 40
#define SALTANEG 41
#define SALTACERO 42
#define ALTO 43
#define TAMANOMEM 99
#define CERO 0
int memoria[TAMANOMEM] = {0};
//Llamada a funciones
int validar(int acumulador);
void CargarPrograma(int[]);
void EjecutarPrograma(int[]);
void imprimir(int acumulador,int contador,int registroInstruccion,int codigoOperacion,int operando,int memoria[]);
//Programa Principal
void main(void) {
CargarPrograma(memoria);
EjecutarPrograma(memoria);
}
//Imprime las instrucciones y cargar las palabras
void CargarPrograma(int memoria[]) {
int i,instruccion;
printf("*** Bienvenido a Simpletron! ***\n");
printf("*** Por favor introduzca a su programa una instrucion ***\n");
printf("*** a la vez (o palabra de datos). ***\n");
printf("*** Yo escribire el numero de ubicacion y un ***\n");
printf("*** signo de interrogacion (?). Usted escriba ***\n");
printf("*** la palabra para dicha ubicacion. Escriba el ***\n");
printf("*** centinela -99999 para terminar la ***\n");
printf("*** introduccion de datos a su programa ***\n");
for(i = 0; i < TAMANOMEM; i++) {
instruccion=0;
do{
if (i<10) printf( "%d%d?",CERO,i);
else {printf("%d?",i);}
scanf("%d",&instruccion);
}while((instruccion<-9999 || instruccion>9999) && instruccion!=-99999);
if (instruccion == -99999) break;
memoria[i] = instruccion;
}
printf("***Carga del programa completada\n***Comienza la ejecucion del programa***");
}
//Valida que el acumulador este dentro del rango
int validar(int acumulador){
int fin;
if(acumulador>9999 || acumulador<-9999){
printf ("***Terminacion anormal del programa***");
fin = CERO;
}
return fin;
}
//Realiza los calculos dependiendo de las palabras ingresadas
void EjecutarPrograma(int memoria[]){
int fin=1;
int contador = 00;
int registroInstruccion = +0000;
int codigoOperacion = 00;
int operando = 00;
int acumulador = +0000;
while(fin!=CERO) {
registroInstruccion = memoria[contador];
codigoOperacion = registroInstruccion/100;
operando = registroInstruccion % 100;
switch (codigoOperacion) {
case LEE: printf("\n?"); scanf("%d",&memoria[operando]); ++contador; break;
case ESCRIBE: printf("%d",memoria[operando]); ++contador; break;
case CARGA: acumulador = memoria[operando]; ++contador; break;
case ALMACENA: memoria[operando] = acumulador; ++contador; break;
case SUMA:
acumulador += memoria[operando];
fin=validar(acumulador);
++contador; break;
case RESTA:
acumulador -= memoria[operando];
fin=validar(acumulador);
++contador; break;
case DIVIDE:
if (memoria[operando] == 0) { printf("Error Intento de division por 0"); return; }
acumulador /=memoria[operando];
fin=validar(acumulador);
++contador; break;
case MULTIPLICA:
acumulador *=memoria[operando];
fin=validar(acumulador);
++contador; break;
case SALTA: contador = operando; break;
case SALTANEG: if(acumulador < 0) contador = operando; ++contador; break;
case SALTACERO: if(acumulador == 0) contador=operando; ++contador; break;
case ALTO: printf ("\n*** Finaliza ejecucion de Simpletron***");
imprimir(acumulador,contador,registroInstruccion,c odigoOperacion,operando,memoria);fin = CERO;
}
}
imprimir(acumulador,contador,registroInstruccion,c odigoOperacion,operando,memoria);
}
//Imprime el vaciado de memoria
void imprimir(int acumulador,int contador,int registroInstruccion,int codigoOperacion,int operando,int memoria[]) {
int i,j;
printf( "\nREGISTROS:" );
printf("\nAcumulador \t\t%d",acumulador);
printf("\nContador \t\t%d",contador);
printf("\nRegistroInstruccion %d",registroInstruccion);
printf("\nCodigoOperacion \t%d",codigoOperacion);
printf("\nOperando \t\t%d",operando);
printf("\nMEMORIA:\n");
for (i=0;i <= 9 ; i++) /*encabezado del 1 al 9*/printf("\t%d",i );
for (i = 0; i <= 9; i++){
printf(" \n%d",i*10);
for (j = 0 ; j <= 9; j++) printf(" +%6d",memoria[10*i+j]);
}
}

Etiquetas: lenguaje, maquina
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:00.