Question #177281

Write an assembly language program that moves the number 2 to BL and 0 to AL. Add BL to AL ECX many times having AL as the destination. Move 10 into ECX before the loop. What will the value of AL when the loop is done?


Expert's answer

global _start


section .data

   str:   DB 30,30,30,10   

   strLen:   EQU $-str


section .text


_start:

   mov   bl,2   ; move the number 2 to BL

   xor   al,al   ; move 0 to AL


   mov   ecx,10

M1:   add   al,bl   ; Add BL to AL

   loop   M1   ; loop ECX many times


   ; convert byte AL to decimal string

   mov   ecx, str


   ; first decimal digit

   xor   ah,ah

   mov   bl,100

   div   bl

   add   al,30h

   mov   [ecx],al


   ; second decimal digit   

   inc   ecx

   mov   al,ah

   xor   ah,ah

   mov   bl,10

   div   bl

   add   al,30h

   mov   [ecx],al


   ; third decimal digit   

   inc   ecx

   mov   al,ah

   add   al,30h

   mov   [ecx],al


   ; output result in AL

   mov   eax, 4

   mov   ebx, 1

   mov   ecx, str

   mov   edx, strLen

   int   80h


   ; exit

   mov   eax, 1

   mov   ebx, 0

   int   80h


; Answer: AL=20





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS