`.model small
.stack 100
.data
kernel DB 10 DUP(1)
input  DB 1, 2, 3, 4, 5, 6, 7
output DB 0, 0, 0, 0, 0, 0, 0
.code

MAIN PROC FAR

MOV AX, @DATA
MOV DS, AX

LEA BX, input
LEA DI, output
MOV AX, 0                       ;1st element starts here
MOV CX, 6
MOV SI, BX
CALL SUM
MOV BH, 6
DIV BH
MOV [DI], AL                    ;1st element ends here

MOV AX, 0           ;2nd, 3rd, 4th and 5th elements start here
MOV CX, 7
MOV SI, BX
CALL SUM
MOV BH, 7
DIV BH
MOV [DI+1], AL
MOV [DI+2], AL
MOV [DI+3], AL
MOV [DI+4], AL          ;2nd, 3rd, 4th and 5th elements start here

MOV AX, 0           ;6th element starts here
MOV CX, 6
MOV DX, BX
INC DX
MOV SI, DX
CALL SUM
MOV BH, 6
DIV BH
MOV [DI+5], AL          ;6th element ends here

MOV AX, 0           ;7th element starts here
MOV CX, 5
MOV DX, BX
INC DX
INC DX
MOV SI, DX
CALL SUM
MOV BH, 5
DIV BH
MOV [DI+6], AL          ;7th element ends here

LEA SI, output
MOV CX, 7
CALL PRINT                      ;print the output array
CALL EXIT           ;exit
    MAIN ENDP

SUM PROC FAR            ;sum procedure to add elements of the input
ADD AL, [SI]
INC SI
DEC CX
JNZ SUM
RET
SUM ENDP            ;sum ends here

PRINT PROC FAR          ;print the output array
MOV DL, [SI]
MOV AH, 2
INT 21H
INC SI
DEC CX
JNZ PRINT
RET
PRINT ENDP

EXIT PROC FAR
MOV AH, 4CH
INT 21H
EXIT ENDP
END MAIN

i'm getting this error` 12.png 12.png

Recommended Answers

All 3 Replies

I think if this is some assignment you posted about before. Not everyone may notice that. But to make a new post leaves you with both posts lacking all the facts. Or questions.

Did you read the link I supplied? Here it is again.

-> Read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

Also, if I were to name the DB areas, input and output are names I'd avoid in most any language today because they are often reserved words. It's a lesson you learn over time. Name your items well and avoid names that could be reserved or too easily confused with words in the language you are programming in.

So down to business. Line 18 looks to read MOV SI, BX but that should spit out an error.

Is your paste job here changing the line numbers that you see and use in your editor?

Last time I used 8086 assembler was when I wrote a TCP/IP stack for QNX in the early 90's (work for the US Navy). At this point, I really can't help you. I occasionally write a few assembly statements when modifying Linux kernel code, but that is very rare these days.

Hmmm... Last time I did any 8086 programming was..., Well, a long time ago.

Your error message seems to give it away though, forward reference. If I recall correctly, subroutines must be declared before they are called.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.