Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

assembly - Where is -32768 coming from?

This is LC3 Assembly code I am working with

.ORIG x3000
LOOP LDI R0, KBSR 
BRzp LOOP

From LC3 Assembly, I know that LDI is a load indirect addressing mode, meaning it read in an address stored at an location and then read the value at that location

From Lc3 Keyboard, I know that KBSR is the keyboard status register, which is one when keyboard has received a new character.

Here is my test run in Lc3 simulator? I entered the character 'a' enter image description here

After executing LDI R0, KBSR, register 0 stores a value of -32768.

Does anyone know, based off my definitions for ldi and KBSR where this number is coming from? I was expecting something like 1 to be stored because the keyboard has received a new character.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In KBSR (keyboard status register) bit 15 is set when a key is read, so you get 0b1000_0000_0000_0000 (or 0x8000) ... which - interpreted as a 2's complemented negative number - happens to be -32768 decimal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...