当前位置:编程学习 > 汇编语言 >>

急!急!急!题目是:计算1+2+……n=?,其中n通过键盘输入。要求用汇编语言中的循环程序设计来实现。

要求在屏幕上提供如下信息: Please input a number(1350): 100 ;出现此信息后通过 键盘输入一个小于628的无符号整数 The sum is: 5050
答案:;1to100
       include io32.inc
       .data
msg1 byte 'Please input a number(1350):',0
msg2 byte 'This sum is:',0
       .code
start:
      mov eax,offset msg1
      call dispmsg
      call readsid
      mov ecx,eax
      mov eax,0
again:add eax,ecx
      loop again
      push eax
      mov eax,offset msg2
      call dispmsg
      pop eax
      call dispsid
      exit 0
end start
其他:mov ah,1
int 21h  ;键盘输入的数n存放在al中
mov ah,0
mov cx,ax  ;将n传给CX中,控制循环次数
mov dx,0   ;存放和
loop:adc dx,cx 看不懂……你不是学这个的么…… (1+n)×(n÷2)

上一个:在汇编语言中经常看到 INT 21H ,这个是什么?什么时候要写它?应写在什么地方?
下一个:汇编语言和c语言的区别,学习那一种更容易对于单片机而已?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,