简体   繁体   中英

How to negate the value in a Register in LC-3 assembly language?

I am new to LC-3 assembly language and writing a program that compares two characters. The program prompts the user to enter in a character to check for (I used GETC to load the user input into R0).

The skeleton code I was given loads the negated value of 'g' into R0, which is given as xFF99 in hex (I'm not sure how this value was obtained, though, as it was given). Then, a separate character is loaded into R7 and to check if they are equal, the program adds R0 to R7 and the result is stored in R0. Then, a branch statement runs if the zero condition code is set.

My question is how do I get the negated value of what a user inputs? All I must do is simply used GETC to get the user input into R0, and then negate that value. After that, the program will work as intended.

LC-3 does not have a negation instruction, nor even a subtraction instruction (,). so instead you need to negate numbers by constructing the 2's complement directly, This entails complementing the bits with the NOT instruction. and then incrementing by 1 with ADD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM