2012-05-10 19 views
1

2つの入力番号を取り、x * y = zを出力するLC3アセンブリ言語プログラムを作成しようとしています。LC3アセンブリ言語

私は数値0-9のために働くことができますが、それ以上の数字は私が奇妙な文字や記号を取得します。

また、GETCにつき1つの入力しか取ることができないようにするにはどうすればよいですか? 10 * 12= 120? ご協力いただければ幸いです! :)

は、ここで私がこれまで行ってきたものだ

.ORIG x3000 
AND R3, R3, #0 ;r3 stores the sum, set r3 to zero 
AND R4, R4, #0 ;r4 is the counter 
LD R5, INVERSE_ASCII_OFFSET ;inverse ascii offset 
LD R6, DECIMAL_OFFSET ;decimal offset 
;--------------------- 
;storing first input digits 
LEA R0, display1 ;load the address of the 'display1' message string 
PUTS ;Prints the message string 
GETC ;get the first number 
OUT ;print the first number 
ADD R1, R0, #0 ;store input value(ascii) to r1 
ADD R1, R1, R5 ;get real value of r1 
;storing second input digits 
LEA R0, display2 ;load the address of the 'display2' message string 
PUTS ;Prints the message string 
GETC ;get the first number 
OUT ;print the first number 
ADD R2, R0, #0 ;store input value(ascii) to r2 
ADD R2, R2, R5 ;get real value of r2 
;---------------------- 
ADD R4, R2, #0 ;fill counter with multiplier 
MULTIPLICATION: 
ADD R3, R3, R1 ;add to sum 
ADD R4, R4, #-1 ;decrease counter by one 
BRp MULTIPLICATION ;continue loop until multiplier is 0 
LEA R0, stringResult 
PUTS 
ADD R0, R3, R6 ;move result to r0 
OUT ;print result 
HALT 
display1 .STRINGZ "\nenter the 1st no.: " 
display2 .STRINGZ "\nenter the 2nd no.: " 
stringResult .STRINGZ "\nResult: " 
INVERSE_ASCII_OFFSET .fill xFFD0 ; Negative of x0030. 
DECIMAL_OFFSET .fill #48 
.END 

答えて

1

あなたの表示機能は、'0'の基本ASCII値に番号を追加することで機能します。これは、asciiテーブルが便利な方法で配置されていたために機能します。たとえば、に相当する'0' + 1 = '1'です。しかし、あなたがおそらくそれを見つける場合は'0' + 12 = '<'。これは、'0' = 0x30なので、0x30 + 12 (0xC) = 0x3Cです。アスキーチャートを見ると、それは0x3C = '<'です。つまり、1桁の数字を印刷するだけの効果的な方法です。

あなたの質問に対する答えは、数字を繰り返し処理して数字を形成するルーチンを書くことです。つまり、次に出力する文字を決定して印刷するループが必要です。

+0

これをご覧になれますか? http://superuser.com/questions/904324/which-of-the-following-instructions-can-reference-a-memory-location-that-is-100 – committedandroider

関連する問題