assembly 高级汇编语言(HLA)的二进制化

nx7onnlm  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(108)

我有如下任务:编写一个HLA汇编程序,提示输入一个int 8值进行检查,然后以二进制格式打印出来。例如,以下是各种输入值的程序输出
给我一个要打印的十进制值:15 15是0000_1111给我一个十进制值打印:0000_0111
(Hint:没有以二进制输出打印的标准输出,所以您需要自己完成此操作。为了实现这一点,您需要每次将一个位移动到进位标志中,并打印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;
o4tp2gmn

o4tp2gmn1#

一个明显的错误是,你是10 BH。这样的东西应该会更好:

shl(1, BH); //1st
lahf();
and( %0000_0001, AH );
stdout.putb(AH);

对其他人重复,或使用循环;)不知道putb使用什么格式,因为你提到得到16个零,我猜它可能是写2个十六进制数字。在这种情况下,检查是否有不同的输出函数(可能是puti8?)。如果没有打印个位数,则打印字符(您必须转换为asm,然后添加'0''1')。

vngu2lb8

vngu2lb82#

stdout.puti8( BH );
stdout.put( " in binary is: %" );

    shl(1, BH); 
    lahf();
    //load AH with Flags
    and( %0000_0001, AH );
    //passing an arugement to AH[0]
    stdout.puti8( AH ); 
    //without i8, it outpouts 2 digits

这输出个位数,我必须做同样的分配,这使它工作。

相关问题