高级汇编 (HLA) 中的十进制到二进制

问题描述 投票:0回答:3

我有以下作业:编写一个 HLA 汇编程序,提示输入要检查的 int8 值,然后以二进制格式打印它。例如,这里是各种输入值的程序输出

给我一个要打印的十进制值:15 15 是 0000_1111 给我一个要打印的十进制值:7 7 是 0000_0111

(提示:没有以二进制输出方式打印的标准输出,因此您需要自己执行此操作。为了完成此操作,您需要一次移动一位到进位标志并打印 0 或 1,具体取决于什么你可以在进位位中找到。移位并重复这个过程 8 次,你就完成了!最终,我们将学习如何循环,使这个任务变得不那么可怕。)

(第二个提示:LAHF 将进位位和所有其他标志从 EFLAGS 寄存器推入 AH。作为一名汇编程序员,您有权通过使用 AND 来屏蔽除您感兴趣的位之外的所有位或或。)这是我目前在课堂上学到的内容: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
3个回答
1
投票

一个明显的错误是您正在覆盖

BH
。像这样的东西应该效果更好:

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

对其他人重复,或使用循环;) 不确定

putb
使用什么格式,因为你提到得到 16 个零,我猜它可能会写 2 个十六进制数字。在这种情况下,请检查您是否有不同的输出函数(也许
puti8
?)。如果没有打印单个数字,则打印字符(您必须转换为 ascii,然后添加
'0'
'1'
)。



-1
投票
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

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

© www.soinside.com 2019 - 2024. All rights reserved.