请教几个 C 的运算符(20分)

  • 主题发起人 tsedlinux
  • 开始时间
T

tsedlinux

Unregistered / Unconfirmed
GUEST, unregistred user!
temp>>=n;
<------这个地方是不是这样 temp=temp>>n ?
temp=temp&amp;0x03;
<------这个地方的&amp;是什么作用?书上说"&amp;"是指针运算符,但是我没找到象这样使用的例子

 
&amp;除了取指针,还是“按位与”,即 按位的and 运算
至于 temp>>=n ,没有这样的运算符号,是错误的表达式
 
补充,按位与,就是比如
0x21 &amp;
0x3 要转换成二进制
00100001 and 0011 = 0001
所以,0x21 &amp;
0x3=1
 
TO pipi
//至于 temp>>=n ,没有这样的运算符号,是错误的表达式
不知道你有没有谭浩强的C程序设计这本书?
刚查到的:
">>="是二元运算符,它相当于TEMP=TEMP>>N,看来学C还是很有用的
 
c的代码:
main()
{
int n;
char cmos;
char result;
char temp=0;
printf("This program only is tested at win98 and award bios!!/n");
printf("The password of the cmos is:");
outportb(0x70,0x1d);
cmos=inportb(0x71);
for(n=6;n>=0;n-=2)
{temp=cmos ;
temp>>=n;
temp=temp&amp;0x03;
printf("%d",temp);
}
outportb(0x70,0x1c);
result=inportb(0x71);
for(n=6;n>=0;n-=2)
{ temp=result;
temp>>=n;
temp=temp&amp;0x03;
printf("%d",temp);
}
}
DELPHI代码:
procedure TForm1.Button1Click(Sender: TObject);
var
a:integer;
al:integer;
ax:integer;
s:integer;
i:integer;
temp:integer;
te:integer;
begin
begin
te:=6;
asm
mov dx,70h
mov al,1dh
out dx,al
mov dx,71h
in al,dx
end;
for i:=0 to 3do
begin

te:=te-2;
temp:=al;
temp:=temp shr te;
temp:=temp and 3;
listbox1.Items.Add(inttostr(temp));
end;
end;

begin
te:=6;
asm
mov dx,70h
mov al,1ch
out dx,al
mov dx,71h
in al,dx
end;
for i:=0 to 3do
begin

te:=te-2;
temp:=al;
temp:=temp shr te;
temp:=temp and 3;
listbox1.Items.Add(inttostr(temp));
end;
end;
end;
是不是有地方改错了?它的结果与C的不一样
 
哦,是的,刚才我没想起来
 
outportb(0x70,0x1c);
result=inportb(0x71);
这两个转成的asm有点问题
1、建议asm的开头、结尾加上pushad、popad
2、popad之前mov cmos,al
 
不行,值还是不一样
 
temp=temp&amp;0x03;
是不是在DELPHI里,0x03也要用16进制数的写 法?
怎么写呢?
 
temp=temp&amp;0x03;
是不是在DELPHI里,0x03也要用16进制数的写 法?
怎么写呢?
哈哈,在Delphi中可以写成: temp:=temp and $03
 
你的al,dx等怎么能够是integer?
建议写成函数形式:
function inportb(port:word):char;
begin
asm
mov dx,port
in al,dx
end
end;

//dx,al是寄存器名,不是delphi的变量
 
c里面n是6、4、2、0
delphi里面是te:=4,2,0,-2
 
begin
te:=6;
asm
mov dx,70h
mov al,1dh
out dx,al
mov dx,71h
in al,dx <<-----------------------------------
end;
for i:=0 to 3do
begin
你怎么知道在这一段程序之间delphi没有使用 AL 呢?
te:=te-2;
temp:=al;
<< ------------------------------------
temp:=temp shr te;
temp:=temp and 3;
listbox1.Items.Add(inttostr(temp));
end;
end;

 
难道DELPHI在汇编里也要插入代码吗?
 
多人接受答案了。
 
顶部