sum 5 numbers in memory and put it to sum assembly language
FIND_SUM: //the label where it starts may change syntax
XOR DX,DX // makes dx = 0
XOR AH,AH // makes AH = 0
PUSH CX // save how many bytes (in your case 5 should be here)
CLD // clear direction flag moves SI to the next byte each load
FIND_SUM_LOOP1:
LODSB // moves first byte into AL
ADD DX,AX // used DX,AX instead of DL,AL so there is no issue of overflow
DEC CL // decrement counter
JNZ FIND_SUM_LOOP1 //if its no zero do the loop
POP CX // reached the end, at this point DX has the total sum
MOV AX,DX // copies the sum into ax (to do the average)
DIV CL // now CL has the average rounded down.
RET // returns from where it was called.
to use this lets suppose you have a variable name so you need to read the efective address of such variable suppose you name it stnumber5
LEA SI,stnumber5
MOV CX,5
CALL FIND_SUM
|