程序计算数字列表的总和 [英] Program to calculate sum of list of numbers
问题描述
我尝试运行此代码,但不知道错误在哪里.
I tried to run this one but I don't know where the error is.
include "emu8086.inc"
ORG 100
.data
ARRAY DB 12H, 24H, 26H, 63H, 25H, 86H, 2FH, 33H, 10H, 35H
SUM DW 0
.code
START: MOV AX, @DATA
MOV DS, AX
MOV CL, 10
XOR DI, DI
MOV BX, OFFSET ARRAY
BACK: MOV AL, [BX+DI]
MOV AH, 00H
MOV SUM, AX
INC DI
DEC CL
JNZ BACK
; print out the number in ax
CALL print_num ; using procedure
RET
END
推荐答案
ORG 100
如果要创建.COM程序,则此ORG
指令的正确值为256,或者以十六进制表示时为100h.您忘记了 h 后缀!
If you're going to create a .COM program then the correct value for this ORG
directive is 256, or 100h when expressed in hexadecimal. You forgot the h suffix!
.COM程序格式也非常简单,您不需要以下任何内容:.data
,.code
,MOV AX, @DATA
和MOV DS, AX
.但是,您应该像在下面的程序中一样,将代码放置在数据之前.
Also the .COM program format is simple enough that you don't need any of the following: .data
, .code
, MOV AX, @DATA
, and MOV DS, AX
. You should however place the code before the data as I did in below program.
MOV SUM, AX
任务是获得和".您需要在此行上使用add
指令.
The task is to get the "sum". You need to use the add
instruction on this line.
CALL print_num
在使用 emu8086.inc 中的 print_num 过程之前,您需要使用DEFINE_PRINT_NUM
和DEFINE_PRINT_NUM_UNS
进行声明.
Before you can use the print_num procedure from emu8086.inc, you need to declare it using DEFINE_PRINT_NUM
and DEFINE_PRINT_NUM_UNS
.
include 'emu8086.inc'
ORG 100h
; code
MOV CL, 10
XOR DI, DI
MOV BX, OFFSET ARRAY
BACK: MOV AL, [BX+DI]
MOV AH, 0
ADD SUM, AX
INC DI
DEC CL
JNZ BACK
CALL print_num
RET ; End of the .COM program
; data
ARRAY DB 12h, 24h, 26h, 63h, 25h, 86h, 2Fh, 33h, 10h, 35h
SUM DW 0
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END
这篇关于程序计算数字列表的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!