微机原理程序题
1. 将下面C语言程序的代码片段转换为功能等价的汇编语言代码片段,其中sign与sinteger
均为双字变量。
if ( sinteger = = 0)
sign = = 0;
else If ( siteger > 0)
sign = 1;
else
sign = -1;
mov eax,sinteger
mov edx,sign
cmp eax,0
jnz L1
mov ebx,0
L1:cmp ebx,0
jl L2
mov ebx,1
L2:mov ebx,-1
2. 将下面C语言程序的代码片段转换为功能等价的汇编语言代码片段,其中ch1与caps均为字节变量。
if (ch1> =’a’ && ch1< =’z’)
caps= =0;
if (ch1> =’A’ && ch1< =’Z’)
caps= =1;
mov ax,ch1
mov bx,caps
cmp ax,a
jb next
cmp ax,z
ja next
mov bx,0
next:cmp ax,A
jl done
cmp ax,Z
ja done
done:
3. 将下面C语言程序的代码片段转换为功能等价的汇编语言代码片段,其中sum与i变量均为双字变量。
sum=0;
for ( i=1;i< =100;i++)
if ( i%2= =0)
sum=sum+i;
mov ecx,i
mov ecx,1
.while(ecx<=100)
mov eax,ecx
xor edx,edx
mov ebx,2
div ebx
cmp edx,0
jnz next
add sum,ecx
next:inc ecx
.endw
1. 能被4整除但不能被100整除,或者年被400整除的年份是闰年。编程写一个完整的程序,求出2012年~2099年中的所有闰年年份,并把它们存放在数组Lyear中。
算法描述
; esi=0;ecx=2012;
; while (ecx<2100)
; { if (year mod 4=0 and year mod 100 <>0) or (year mod 400=0) then
; {Lyear[esi]=ecx;esi++;}
; ecx++;
; }
; Lcounter=esi;
include io32.inc
.data
Lyear dword 100 dup(?)
Lcounter dword 0
.code
mainproc
xoresi,esi ;esi闰年个数计数器,兼做Lyear下标。
movecx,2012 ;ecx年份计数器。
.while (ecx<2100)
moveax,ecx
xoredx,edx
movebx,400
divebx
cmpedx,0
jzleap;if year mod 400=0 then goto leap
moveax,ecx
xoredx,edx
movebx,4
divebx
cmpedx,0
jnznext;if year mod 4<>0 then goto next
moveax,ecx
xoredx,edx
movebx,100
divebx
cmpedx,0
jznext;if year mod 100=0 then goto next
leap: movLyear[esi*4],ecx
incesi
moveax,ecx
calldispuid;输出,用于验证。可以删掉
calldispcrlf ;输出,用于验证。可以删掉
next:incecx
.endw
movLcounter,esi
moveax,esi
calldispuid ;输出,用于验证。可以删掉
calldispcrlf ;输出,用于验证。可以删掉
ret
mainendp ;end of main
end main ;end of assembly