用汇编语言编程求1+2+3+...+10000=?
ORG 0000HLJMP MAINORG 000BHLJMP T0ISRORG 0030HMAIN:MOV TMOD,#01HMOV TH0,#HIGH(65536-10000)MOV TL0,#LOW(65536-10000)SETB ET0SETB EAMOV R0,#9MOV R1,#9MOV R2,#0MOV R3,#9CLR 00HCLR 01HLOOP:JB P1.0,LP01JNB P1.0,$SETB TR0CLR 01HSJMP LOOP0LP01:JB P1.1,LP02JNB P1.1,$SETB 01HSJMP LOOP0LP02:JB P1.2,LP03JNB P1.2,$SETB 01HINC R0CJNE R0,#10,LOOP0MOV R0,#0SJMP LOOP0
LP03:JB P1.3,LOOP0JNB P1.3,$SETB 01HINC R1CJNE R1,#10,LOOP0MOV R1,#0
LOOP0:JB 00H,LOOP1MOV A,R0SJMP LOOP2LOOP1:MOV A,R1LOOP2:MOV DPTR,#TABLEMOVC A,@A+DPTRMOV R3,ASJMP LOOPT0ISR:CLR TR0MOV TH0,#HIGH(65536-10000)MOV TL0,#LOW(65536-10000)SETB TR0JB 01H,T0CINC R2T0C:CPL 00HMOV A,R3JB 00H,T001MOV P3,#0FDHMOV P2,ASJMP T002T001:MOV P3,#0FEHMOV P2,AT002:MOV A,R2CJNE A,#100,T0EMOV R2,#0MOV A,R0JZ T003DEC R0SJMP T0ET003:MOV A,R1JZ T004DEC R1MOV R0,#9T0E:RETIT004:CLR TR0RETITABLE: ; 共阴极数码管显示代码表DB 3FH,06H,5BH,4FH,66H ;01234DB 6DH,7DH,07H,7FH,6FH ;56789
END
仅仅是初始化?
MOV TMOD, #05H
MOV TH0, #(65536 - 100000) / 256
MOV TL0, #(65536 - 100000) MOD 256
SETB TR0
初始化完毕。
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START: JMP BBB
X DD 0
BBB:
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,10000
MOV WORD PTR [X],0
MOV WORD PTR [X+2],0
@MAIN:
ADD WORD PTR [X],CX
ADC WORD PTR [X+2],0
LOOP @MAIN
MOV AX,WORD PTR [X]
MOV DX,WORD PTR [X+2]
CALL DISPDXAX
MOV AH,4CH
INT 21H
;========================================
; 将要显示的32位无符号数置于dx、ax中
DISPDXAX PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSHF
MOV WORD PTR [Y],AX
MOV WORD PTR [Y+2],DX
; 以下将 Y (16进制)转为10进制串并输出
MOV AX,WORD PTR [Y]
MOV DX,WORD PTR [Y+2]
MOV BX,WORD PTR [Z]
MOV CX,WORD PTR [Z+2]
MOV WORD PTR N,0
MM0: INC WORD PTR N
SUB AX,BX
SBB DX,CX
JNC MM0
DEC WORD PTR N
ADD AX,BX
ADC DX,CX
MOV WORD PTR[Y],AX
MOV WORD PTR[Y+2],DX
;==============
MM1: LEA DI,CC
ADD DI,9
M2:
MOV AX,WORD PTR [Y]
MOV DX,WORD PTR [Y+2]
MOV BX,10000
DIV BX
PUSH AX
PUSH DX
; ============
; 以下转换10进制的低4位
POP DX
MOV CX,4
MOV AX,DX
M3: MOV DX,0
MOV BX,10
DIV BX
ADD DL,30H
MOV [DI],DL
DEC DI
LOOP M3
; ===========
; 以下转换10进制的高万位
POP AX
MOV CX,1
M4: MOV DX,0
MOV BX,10
DIV BX
ADD DL,30H
MOV [DI],DL
DEC DI
LOOP M4
;=============
MOV AX,WORD PTR N
MOV CX,5
M5: MOV DX,0
MOV BX,10
DIV BX
ADD DL,30H
MOV [DI],DL
DEC DI
LOOP M5
; ============
; 输出换行回车
LEA DX,LFCR
MOV AH,9
INT 21H
; ============
; 输出两数的和的10进制串
MOV CX,9
LEA SI,CC
M6:
MOV AL,[SI]
CMP AL,'0'
JNE M7
MOV BYTE PTR [SI],32
INC SI
LOOP M6
M7:
LEA DX,CC
MOV AH,9
INT 21H
POPF
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
Y DD ?
CC DB 10 DUP(' '),10,13,'$'
LFCR DB 10,13,'$'
Z DD 100000
N DW 0
DISPDXAX ENDP
CODE ENDS
END START
1+2!+3!+…… +20!
以下是用C语言编程求出1!+2!+3!+……+20!的值示例代码:include <stdio.h> int main(){ int i,j;long sum,k;sum=0;for(i=1;i<=20;i++){k=1;for(j=1;j<=i;j++){ k=k*j;} sum=sum+k;} printf("1+2!+3!+…+20!=%d",sum);} ...
编程计算S=1+2+3+…+100的值
int s=0;for(int i=0;i<100;i++){ s+=i;} System.out.print(s);
编写程序,求1+2+3……+50,结果放在SUM单元中
include "stdio.h"include "conio.h"int sum(int n){ int s=0;if(n>0){ s=sum(n-1)+n;n--;} return s;};main(){ int n=50;printf("%d\\n",sum(n));getch();}
汇编语言实现一到十相加的和
dseg segment msg db '1+2+3+...+10=$'dseg endsassume cs:cseg, ds:dseg cseg segmentstart: mov ax, dseg mov ds, ax lea dx, msg mov ah,9 int 21h mov cx, 10 ;控制长度 mov ax, 0 ;保存计算结果 mov bx, 1 ;从1开始累加 loop0: add ax, bx...
用80C51单片机 汇编语言 计算 1+2+3+4+5+...+10的结果, (不要告诉...
分太少了,加点分吧!org 0 mov r0,#10 ;共10个数 mov a,#0 ;累加结果先清0 mov r1,#1 ;第1个数为1 loop:add a,r1 ;把数累加起来 inc r1 ;下一个数 djnz r0,loop;共10个数,未完转 LOOP循环 sjmp $ ;完成 end
用汇编语言实现如下程序:进行自然数相加(1+2+3+……+N)。必须利用循环...
0 MOV DX,0 MOV SI,0 MOV DI,0 MOV CX,WORD PTR @N MOV BX,WORD PTR @N+2 @0: ADD AX,SI ADC DX,DI JC @ERR ADD SI,1
编程实现sum=1+2+3+…+N,N=学号最后两位+20.要求从汇编语言程序调用C...
;添加你的代码xorax,axxorbx,bxmovcx,100l1:incbxaddax,bxloopl1movsum,axmovbx,axmovcx,16;2进制打印到屏幕上print:movah,2movdl,'0'testbx,1000000000000000bjzzeromovdl,'1'zero:int21hshlbx,1loopprintmovdl,'b'int21h;结果为:0001001110111010bmovah,4chint21h ...
1+2+3+...+10用汇编语言
STACK SEGMENT STACK DW 64 DUP(?) DATA SEGMENT DATA ENDS CODE SEGMENT ASSUME CS:CODE START: MOV AL,2 MOV DX,1 LOOP: MOV BL,AL INC BL MUL BL MOV CL,AL ADD DX,AX MOV AL,BL CMP CL,200 JC LOOP A1: JMP A1 CODE ENDS END START ...
求助:请高手用汇编语言编程下面这一题,求出1+2+3+4+...+99+100的和...
DATA SEGMENT RESULT DW 0 s1 db 0,0,0,0,'$'DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA BEGIN:mov ax,data mov ds,ax mov es,ax MOV AX,0 MOV BX,0 MOV CX,100 LP: INC BX ADD AX,BX LOOP LP MOV RESULT,AX mov cx,4 lea si,s1 l1: rol ax,1 rol ax,1 rol ax,...
汇编语言1加到10的程序
next:add ax, cx; 求和 loop next aam ;二化十 add ax,3030h;转为ASCII xchg ah,al mov dx,ax;送入DX待显示 mov ah,2 int 21h;显示高位 mov dl,dh int 21h;显示低位 mov ah,1 int 21h;暂停 mov ax, 4c00h int 21h ;结束 mes db '1+2+3+...+10=$'code ends end start ...