2

R1 と R2 の 2 つの数値を比較し、R1 = R2 の場合は値 0、R1 > R2 の場合は 1、R1 < R2 の場合は -1 を R0 に入れる単純な LC-3 プログラムを作成するにはどうすればよいでしょうか。

4

2 に答える 2

0
.ORIG x3000
AND R1, R1, x0
AND R2, R2, x0
LD R6, RESET
LEA R0, LINE1
PUTS
GETC 
OUT
ADD R1, R6, R0

LEA R0, LINE2
PUTS
GETC
OUT
ADD R2, R6, R0

JSR COMPARE
HALT
;////////// COMPARE FUNCTION BEGINS /////////////
COMPARE 
      AND R3, R3, x0
      NOT R2, R2
      ADD R2, R2, x1
      ADD R3, R1, R2
     BRn NEG
      ADD R3, R3, x0
     BRp POS
      ADD R3, R3, x0
     BRz EQ
      AND R5, R5, x0
      ADD R5, R5, R1
     RET
  NEG LEA R0, N ; triggers when R3 IS NEGATIVE
      PUTS
      RET
  POS LEA R0, P ; triggers when R3 IS POSITIVE
      PUTS
      RET
  EQ  LEA R0, E ; triggers when R3 IS ZERO
      PUTS
      RET

N .STRINGZ "\nX IS LESS THAN Y"
P .STRINGZ "\nX IS GREATER THAN Y"
E .STRINGZ "\nX IS EQUAL TO Y"
RESET .FILL xFFD0; RESET = -48 AS THIS IS ASCII RESETER FOR OUR PROGRAM
LINE1 .STRINGZ "ENTER X : "
LINE2 .STRINGZ "\nENTER Y : "
.END    
于 2017-04-20T14:56:08.857 に答える