如何编写一个使用LC3中的循环将"Hello World"打印5次的程序? [英] How do I write a program that prints out “Hello World”, 5 times using a loop in LC3?

查看:955
本文介绍了如何编写一个使用LC3中的循环将"Hello World"打印5次的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.ORIG x3000
COUNTER .FILL x0005
LEA R0, HELLO_WORLD  
PUTS
HALT
HELLO_WORLD .stringz "Hello World this is John Cena!"
.END

到目前为止,这是我只写一次名称的代码,我对如何在该代码中实现循环感到困惑,因此该名称将被显示5次.

This is the code I have so far for just writing the name once, I'm confused how to implement the loop into this code so that the name will be displayed 5 times.

推荐答案

打印Hello World!使用循环5次:

; +++ Intro to LC-3 Programming Environment +++

; Print "Hello World!" 5 times
; Use Loops to achieve the aforementioned output

; Execution Phase
.ORIG x3000 

LEA R0, HELLO   ; R0 = "Hello....!"
LD R1, COUNTER  ; R1 = 5

LOOP TRAP x22   ; Print Hello World
ADD R1, R1, #-1 ; Decrement Counter
BRp LOOP    ; Returns to LOOP label until Counter is 0 (nonpositive)

HALT

; Non-Exec. phase

HELLO .STRINGZ "Hello World!\n" ; \n = new line
COUNTER .fill #5        ; Counter = 5

.END    ; End Program

祝您工作顺利,学习LC-3汇编语言! :D

这篇关于如何编写一个使用LC3中的循环将"Hello World"打印5次的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆