我正在尝试获取一个字节的信息,对它们进行真正的编号和比较。
我的比较产生了错误的输入。这是代码。
program dateDemo;
#include ("stdlib.hhf")
static
dayR: byte;
monthR: byte;
yearR: word;
day: uns8;
month: uns8;
year: uns16;
packedDate: dword;
begin dateDemo;
stdout.put( "Enter the current month, day, and year: " );
stdin.get( monthR, dayR, yearR );
mov( 0, eax );
mov(0, bx);
mov( eax, packedDate ); // Just in case there is an error.
mov(monthR, ah);
mov(ah, month);
mov(dayR, al);
mov(al, day);
mov(yearR, bx);
mov(bx, year);
// Pack the data into the following bits:
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// m m m m d d d d d y y y y y y y
if( month > 12 ) then
stdout.put( "Month value is too large", nl );
elseif( month = 0 ) then
stdout.put( "Month value must be in the range 1..12", nl );
elseif( day > 31 ) then
stdout.put( "Day value is too large", nl );
elseif( day = 0 ) then
stdout.put( "Day value must be in the range 1..31", nl );
elseif( year > 99 ) then
stdout.put( "Year value must be in the range 0..99", nl );
else
stdout.put("It worked");
/*mov( month, al );
shl( 5, ax );
or( day, al );
shl( 7, ax );
or( year, al );
mov( ax, packedDate );*/
endif;
我遗漏了一些无关紧要的代码。如果我输入“10 20 1997”,它会输出“月份太大”,我尝试使用 uns8 而不是 hte 字节信息进行比较,但无济于事。谁能给我提示。
我的年份也将达到 2000 年,因此它将使用一个完整的 16 位字。
最佳答案
环境
版本 2.16 build 4413(原型(prototype))
注意
解决方案
word
日期表示,因此应将示例更改为使用 dword
如果您想使用 word
的长压缩日期格式为您的年份值(value)。 |31 . . . . . . . . . . . . . . 16|15 . . . . . . 8|7 . . . . . . 0|
| y y y y y y y y y y y y y y y y | m m m m m m m m|d d d d d d d d|
示例
dword
而更改的 demoDate 示例。长包装日期格式。 program LongDateDemo;
#include ("stdlib.hhf")
storage
Day: uns8;
Month: uns8;
Year: uns16;
LongPackedDate: dword;
begin LongDateDemo;
stdout.put("Enter the current month, day, and year (EX: 6 14 2020): ");
stdin.get(Month, Day, Year);
// Long packed date format
// |31 - 16|15 - 8|7 - 0|
// |year |month |day |
mov(0, EAX);
mov(EAX, LongPackedDate ); // Just in case there is an error.
if( Month > 12 ) then
stdout.put( "Month value is too large", nl );
elseif( Month = 0 ) then
stdout.put( "Month value must be in the range 1..12", nl );
elseif( Day > 31 ) then
stdout.put( "Day value is too large", nl );
elseif( Day = 0 ) then
stdout.put( "Day value must be in the range 1..31", nl );
elseif( Year > 65535 ) then
stdout.put( "Year value must be in the range 0..65535", nl );
else
mov(Year, AX);
shl(8, EAX);
or(Month, AL);
shl(8, EAX);
or(Day, AL);
mov(EAX, LongPackedDate);
endif;
// Okay, display the packed value:
stdout.put("Packed data = $", LongPackedDate, nl);
// Unpack the date:
mov(LongPackedDate, EAX);
and($FF, AL); // Retrieve the day value.
mov(AL, Day);
mov(LongPackedDate, EAX);
shr(8, EAX);
and($FF, AL); // Retrieve the month value.
mov(AL, Month);
mov(LongPackedDate, EAX);
shr(16, EAX);
and($FFFF, AX); // Retrieve the year value.
mov(AX, Year);
stdout.put("The date is: ", Month, "/", Day, "/", Year, nl);
end LongDateDemo;
关于assembly - 如何处理以字节为单位的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52472195/