Write an LC3 program that determine if the content of memory

Write an LC3 program that determine if the content of memory location x3100 is odd Store x0001 in memory location x3101. Also count the number of 1s in memory location x3100 and store the count in x3102. Store your Machine Language program originate at x3000.

Please provide explanation of the code with a FLOW CHART. thank you!

Solution

Below is the solution to your question:

·         In binary,if a number is even it ends with a 0, and if it is odd, it ends with a 1.

·         We can obtain 0 or 1 by using AND instruction i.e AND R2 , R1 , x0001 ; R2 has the value of the least 2 ; significant bit of R1;

·         Below is the program:

Values of X and Y are loaded into registers R1 and R3

1.ORIG x3000 ;This is the address where the program actually begins

2.LEA R2 , xFF ; R2 x3000 + x1 + xFF (= x3100 )

3.LDR R1 , R2 , x0 ; R1 MEM[ x3100 ]

4.LDR R3 , R2 , x1 ; R3 MEM[ x3100 + x1 ]. . .

5.AND R4 , R4 , x0 ; Clear R4

6.ADD R4 , R4 , x5 ; R4 5

7.STR R4 , R2 , x1 ; MEM[ x3100 + x1 ] R4

AND R2 , R1 , x0001 //Determining whether a number is odd or even

·         Explaination:

·         1.Register R2 is loaded with the beginning address.

·         2.R2 x3000 + x1 + xFF (= x3100 )

·         3.X, which is located at x3100 , is loaded into Register R1

·         4.; Y, which is located at x3101,this value is stored into register R3

·         5.Storing 5 in memory location x3101

·         6.Clear register R4

·         7.R4 5

·         8.MEM[ x3100 + x1 ] R4

Example Run with the values given above:

Address

x3100        Decimal 9         Hex 0009    binary 0000 0000 0000 1001       Contents     X

Address

x3101        Decimal -13        Hex FFF3     binary 1111 1111 1111 0011    Contents        Y

Address

x3102         Decimal -4         Hex FFFC     binary 1111 1111 1111 1100    Contents    X +Y

Address

x3103           Decimal 1         Hex 0001    binary 0000 0000 0000 0001   Contents     X AND Y

Address

x3104        Decimal -5          Hex FFFB     binary 1111 1111 1111 1011   Contents      X OR Y

Address

x3105      Decimal 65526    Hex FFF6      binary 1111 1111 1111 0110   Contents    NOT(X)

Address

x3106   Decimal 12    Hex 000C    binary 0000 0000 0000 1100     Contents    NOT(Y)

Address

x3107    Decimal 12    Hex 000C    binary 0000 0000 0000 1100   Contents X +3

Address

x3108    Decimal -16    Hex FFF0    binary 1111 1111 1111 0000   Contents    Y 3

Address

x3108    Decimal 1    Hex 0001     binary 0000 0000 0000 0001   Contents z   

Write an LC3 program that determine if the content of memory location x3100 is odd Store x0001 in memory location x3101. Also count the number of 1s in memory l
Write an LC3 program that determine if the content of memory location x3100 is odd Store x0001 in memory location x3101. Also count the number of 1s in memory l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site