c语言与微机原理试题,微机原理程序题.doc

微机原理程序题

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值