Can somebody help me translate this code into lower level language? Here is the
ID: 641359 • Letter: C
Question
Can somebody help me translate this code into lower level language?
Here is the OPCODE / INSTRUCTIONS
#define HALT 0 /* halt the machine */
#define LOAD 1 /* load accumulator from memory */
#define STORE 2 /* store accumulator to memory */
#define ADDC 3 /* add counter to accumulator */
#define MVAC 4 /* move accumulator to counter */
#define JEQ 5 /* jump to address if counter equals 0 */
#define JLT 6 /* jump to address if counter is less than 0 */
#define JMP 7 /* jump to address */
#define ADD 8 /* accumulator = memory + accumulator */
#define SUB 9 /* accumulator = memory - accumulator */
#define DEC 0xA /* decrement counter */ /* LA takes the memory address from the instruction and loads it into the accumulator (load address) */
#define LA 0xB /* LIA uses the memory address in the areg to load memory into the accumulator (load indirect address) */
#define LIA 0xC /* SIA stores the value in the accumulator in the memory address found in the areg (store indirect address) */
#define SIA 0xD /* MVAA moves the value in the accumulator to the areg */
#define MVAA 0xE
EXAMPLE INSTRUCTIONS:
0X1004 # LOAD 4
0X5024 # JEQ 0X24
0X4000 # MVAC
Here is the code to translate to lower level language (Assembly)
LARGEST=array[0];
for (i=1;i
if (array[i] > LARGEST) {
TEMP=array[i];
array[i]=LARGEST;
LARGEST=TEMP;
}
array[0]=LARGEST;
Here is a sample:
Code:
result = b-c-ans
if (result<0)
result = -result;
else
result+=a;
TRANSLATION:
0x1010 # LOAD ANS
0x8011 # ADD C
0x9012 # SUB B
0x2013 # STORE RESULT
0x4000 # MVAC
0x600A # JLT
0x1015 # LOAD a
0x8013 # ADD RESULT
0x2013 # STORE RESULT
0X700D # JMP END
0x1013 # LOAD RESULT
0x9014 # SUB zero
0x2013 # STORE RESULT
0x0000 # HALT
0x0000
0x0000
0x1 # ANS
0x1 # C
0x3 # B
0x0 # result
0x0 # zero
0x1 # a
Explanation / Answer
hope this code will helps you ...