你会如何​​去存储的十六进制值转换为它的使用LC3 /装配code二进制数? [英] How would you go about converting a stored Hex value to it's binary equivalent using lc3/assembly code?

查看:684
本文介绍了你会如何​​去存储的十六进制值转换为它的使用LC3 /装配code二进制数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的值存储在一个.BLKW对象并在用LDR R0,R1,0一个LOOP被加载 - ADD R1,R1,1(递增.BLKW地址)。问题是你如何转换转换存储的十六进制值他们的二进制值,然后输出到16位二进制格式控制台。任何想法将大大AP preciated!我想过AND运算值,但我不知道该如何去做。

The values are stored in a .BLKW object and are loaded in a LOOP with LDR R0,R1,0 - ADD R1,R1,1 (to increment the .BLKW address). The problem is how do you convert the stored HEX values to their binary values, and then output the conversion to the CONSOLE in 16-bit binary format. Any ideas will be greatly appreciated! I've thought about ANDing values, but am unsure how to go about it.

推荐答案

您已经有了循环下去。然而,一个小错误。结果
我们知道,当我们使用OUT进行打印,其打印在R0到控制台的值。因此,我们打印数(R0数)应该始终为0或1。因此,我们正在处理的十六进制值应存放在其他一些寄存器,像R2。因此,code按钮LDR R0,R1,0变成LDR R2,R1 0。

You've already got the loop down. However, one small error.
We know that when we use OUT to print, it prints the value in R0 to the console. So, the number we're printing (the number in R0) should always be 0 or 1. Thus, the hex value we're working on should be stored in some other register, like R2. So, the code "LDR R0, R1, 0" becomes "LDR R2, R1, 0".

现在,每个单词(又名在.BLKW地址),您必须将其转换为二进制,一次打印一个位。

Now, for each word (aka address in the .BLKW) you have to convert it to binary, printing one bit at a time.

您可以做16和操作。检查,如果[16](最左位)是一种由AND运算R2与1000 0000 0000 0000数如果结果不为0,那么你知道最左边的位是1,因此,打印1如果结果为0,则知道它必须是零,所以打印0,然后和R2与0100 0000 0000 0000来检查第二位以相同的方式,等等。

You could do 16 AND operations. Check if the [16] (the left-most bit) is one by ANDing R2 with the number with 1000 0000 0000 0000. If the result isn't 0, then you know the left-most bit is a 1, so print 1. If the result is 0, you know it must be zero, so print 0. Then AND R2 with 0100 0000 0000 0000 to check the second bit in the same manner and so forth.

不过,这只是混乱。最好的办法是使用一个循环

However, that's just messy. The best way is to use a loop.

设置寄存器中的一个 - 比方说R3,1000 0000 0000 0000我们会在一分钟内用此

Set one of the registers - let's say R3, to 1000 0000 0000 0000. We'll be using this in a minute.

让我们使用R5作为我们的哨兵,又名计数器,告诉我们,当我们处理的所有16位。我们将设置R5为16,然后从R5我们每次通过循环时间去减1,当我们打到0,我们将退出循环。

Let's use R5 as our sentinel, aka "counter", to tell us when we've processed all 16 digits. We'll set R5 to 16, then subtract 1 from R5 each time we go through the loop, and when we hit 0, we'll exit the loop.

现在,放什么在循环中。

Now, what to put inside the loop.

有关每次迭代中,R2和R3,以及结果存储在像R4一些未使用的寄存器。如果结果是零,我们知道R2的最左边的位是零,因此,打印0.如果结果是否定的(因为1000 0000 0000 0000是一个2的补数,因此负),我们知道左位是1,让打印1。

For each iteration, AND R2 and R3, and store the result in some unused register like R4. If the result is zero, we know the left-most bit of R2 is zero, so print 0. If the result is negative (because 1000 0000 0000 0000 is a 2's complement number and thus negative), we know the left-bit is a 1, so print 1.

然后做在R2的左逐位转变。这是通过添加R2至本身,并通过将其存储完成:ADD R2,R2,R2

Then do a left bit-wise shift in R2. This is accomplished by adding R2 to itself and storing it via: "ADD R2, R2, R2".

递减计数器我们在R5通过:ADD R5,R5,#-1

Decrement our counter in R5 via : "ADD R5, R5, #-1"

返回到循环的开始。

结果应该是你所需要的。

The result should be what you need.

这篇关于你会如何​​去存储的十六进制值转换为它的使用LC3 /装配code二进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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