1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

LC3 question

  1. Feb 27, 2016 #1
    Mod note: Edited the post to add code tags, and moved the code to the attempt section.
    1. The problem statement, all variables and given/known data
    Hi I am trying to write a program in LC3 which performs the operation AND on the input given by the user and the test input highlighted on the next code . The problem that I am having is that the register R0 doesn't seem to change in the console. I try to AND R0 with 0 to see if it reacts and still doesn't work. It preserves the value X7FFF. The reason why I am ANDing the input given by the user and values like this 1000 0000 0000 0000 is because I am trying to display on the screen the number given by the user in binary.

    2. Relevant equations



    3. The attempt at a solution
    Code (Text):

    .ORIG x3000
    LD R0,ZERO
    LD R2,ZERO ;INT
    LD R3,ZERO  ;INT
    LD R4,ZERO  ;DIGIT
    LD R5,ZERO ;LF
    LD R6,FORTYFIVE ;45 48 AND COUNTER

    LOOP TRAP x20
         TRAP x21
         AND R5,R5,#0
         ADD R5,R0,xFFF6
         BRz NEXT3
         ADD R3,R0,R6
         BRnp NEXT
         AND R3,R3,#0
         ADD R3,R3,#1
         BRnzp LOOP

    NEXT AND R6,R6,#0
         LD R6,FORTYEIGHT
         ADD R4,R0,R6
         AND R5,R5,#0
         ADD R5,R5,R2
         AND R6,R6,#0
         ADD R6,R6,#9

    DIGIT BRz NEXT2
          ADD R2,R2,R5
          ADD R6,R6,#-1
          BRnzp DIGIT

    NEXT2 ADD R2,R2,R4
          BRnzp LOOP

    NEXT3 AND R4,R4,#0
          AND R6,R6,#0
          LD R4,x0050   ------>Test Input
          LD R6,FORTYEIGHT_
          AND R0,R2,R4
          BRnp GO
          AND R0,R0,#0
          LD R0,ZERO
          ADD R0,R0,R6
    GO    AND R0,R0,#0
          LD R0,ZERO
          ADD R6,R6,#1
          ADD R0,R0,R6
           OUT
    HALT
    ENTER .STRINGZ "ENTER A NUMBER OR PRESS X TO EXIT: "
    ZERO .FILL #0
    NINE .FILL #9
    FORTYFIVE .FILL #-45
    FORTYEIGHT .FILL #-48
    FORTYEIGHT_ .FILL #48
    .END
     
    Last edited by a moderator: Feb 28, 2016
  2. jcsd
  3. Feb 28, 2016 #2

    Mark44

    Staff: Mentor

    I've never heard of LC3, but I have pretty good knowledge of several kinds of assembly language.

    Is the input being done in one of the trap instructions? The best advice I can give you is to look at the documentation for the LC3 instruction set, particularly the instructions that are used for input. Possibly the instruction you're using is character input instead of integer input. It would be helpful if you can provide a link to the instruction set.
     
  4. Feb 29, 2016 #3
    Hello, thanks!!!, now I am having a weird problem. It looks like when I run a certain code in LC3, it replicates document folders in a mysterious way. Can assembly language code affect my pc if I don't use it properly?
     
  5. Feb 29, 2016 #4

    Mark44

    Staff: Mentor

    It can if one of the trap instructions calls into the operating system to create a new directory.

    I wrote some x86 assembly code years ago that was buggy. Instead of doing what I intended, my code deleted the contents of a floppy disk. Luckily it was only a floppy disk that was affected, not the hard drive.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: LC3 question
  1. MOSFET Question (Replies: 3)

  2. Dynamics question (Replies: 11)

  3. SIMetrix question (Replies: 2)

  4. PLA question (Replies: 2)

  5. Cantilever Question (Replies: 5)

Loading...