Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

DON\'T ANSWER IF U DON\'T KNOW , kept getting random copy and pasted stuff from

ID: 3801388 • Letter: D

Question

DON'T ANSWER IF U DON'T KNOW, kept getting random copy and pasted stuff from internet that doesn't work...

---------------------------------------------------------------------------------

I'm trying to find sum from 1 to 10 in assembly. Should equal 55. But I kept getting g6. Can someone fix my .asm code. Thanks.

---------------------------------------------------------------

section   .text
global _start ;must be declared for linker (ld)
  
_start:  
       
mov eax,10 ;number bytes to be summed
mov ebx,0 ;EBX will store the sum
mov ecx, x ;ECX will point to the current element to be summed

top: add ebx, [ecx]

add ecx,1 ;move pointer to next element
dec eax ;decrement counter
jnz top ;if counter not 0, then loop again

done:

add ebx, '0'
mov [sum], ebx ;done, store result in "sum"

display:

mov edx,1 ;message length
mov ecx, sum ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
  
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel

section   .data
global x
x:
db 1
db 2
db 3
db 4
db 5
db 6
db 7
db 8
db 9
db 10

sum:
db 0

Explanation / Answer

DATA SEGMENT A DB 1,2,3,4,5,6,7,8,9,10 SUM DB ? DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START: MOV AX,DATA MOV DS,AX LEA BX,A MOV CL,10 MOV AX,0000 L1:ADD AL,BYTE PTR[BX] INC BX DEC CL CMP CL,00 JNZ L1 MOV SUM,AL MOV BH,10 DIV BH MOV AH,4CH INT 21H CODE ENDS END START ;OUTPUT:->