【发布时间】:2016-01-10 05:05:55
【问题描述】:
我有以下任务:编写一个 HLA 汇编程序,提示输入一个 int8 值进行检查,然后以二进制格式打印它。例如,这里将是各种输入值的程序输出
给我一个十进制值打印:15 15 是 0000_1111 给我一个十进制值打印:7 7 是 0000_0111
(提示:没有以二进制输出打印的标准输出,因此您需要自己执行此操作。为了完成此操作,您需要不时向进位标志移动一点并打印 0 或 1,具体取决于根据您在进位位中找到的内容。移位并重复此过程 8 次,您就完成了!最终,我们将学习如何循环,使这项任务变得不那么可怕。)
(第二个提示:LAHF 将进位位和所有其他标志从 EFLAGS 寄存器中推到 AH 中。作为汇编程序员,您有能力屏蔽除您感兴趣的位之外的所有位AND 或 OR。)这是我目前在课堂上学到的内容:http://homepage.smc.edu/stahl_howard/cs17/FileManager/referenceguides/referenceguideii.htm 到目前为止,我的代码是这样的,我认为这是一个逻辑错误,因为无论我输入什么数字,我都会得到一串 16 个 0。
begin program BinaryOutput;
#include( "stdlib.hhf" );
static
iDataValue : int8; // the value to inspect
begin BinaryOutput;
stdout.put( "Gimme a decimal value to print: ", nl);
stdin.get( iDataValue );
mov(0, BH);
mov( iDataValue, BH);
stdout.put("Number in binary is: ", nl);
shl(1, BH); //1st
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //2nd
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //3rd
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //4th
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //5th
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //6th
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //7th
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
shl(1, BH); //8th
lahf();
and( %0000_0001, AH );
mov(AH, BH);
stdout.putb(BH);
end BinaryOutput;
【问题讨论】:
标签: assembly binary decimal low-level hla