2012-05-10 4 views
1

두 개의 입력 번호를 사용하여 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'0x30 + 1 = 0x31과 같습니다. 그러나, 당신이 아마 그 '0' + 12 = '<'을 찾는다면. '0' = 0x30이므로 0x30 + 12 (0xC) = 0x3C입니다. 아스키 차트를 보면 0x3C = '<'입니다. 즉, 이것은 한자리 숫자 만 인쇄하는 효과적인 방법입니다.

두 가지 질문에 대한 답은 반복적으로 숫자를 처리하고 숫자를 형성하는 루틴을 작성하는 데 있습니다. 즉, 다음에 인쇄 할 문자를 결정하고 인쇄하는 루프가 필요합니다.

+0

이걸 살펴볼 수 있습니까? http://superuser.com/questions/904324/which-of-the-following-instructions-can-reference-a-memory-location-that-is-100 – committedandroider