开发者

Anything wrong with the assmbly code to count number of positive element in list

开发者 https://www.devze.com 2023-02-09 20:48 出处:网络
Can please advice anything wrong with below assmbly code using tasm, i can not get any output at all as below.

Can please advice anything wrong with below assmbly code using tasm, i can not get any output at all as below.

From tasm output

D:\tasmzip\tasmzip>tasm test1.asm
Turbo Assembler  Version 1.0  Copyright (c) 1988 by Borland International

Assembling file:   TEST1.ASM
Error messages:    None
Warning messages:  None
Remaining memory:  453k


D:\tasmzip\tasmzip>tlink test1.obj
Turbo Link  Version 2.0  Copyright (c) 1987, 1988 Borland International

D:\tasmzip\tasmzip>test1

D:\tasmzip\tasmzip>

My code:

ASSUME  CS:CODE , DS : DATA
ORG 0000H
DATA SEGMENT
    LIST DB 2,23,11,7,5,25,13,18,0    ; Given Array with last element zero to indicate end of array
 DATA ENDS
CODE SEGMENT  
    ORG 2000H

   START :  lEA SI , list

    MOV CL,0
    MOV AL,0 

    AGAIN: CMP AL,[SI]  ; look for end of 
     JE over
     INC SI  
     INC CL
     Jmp AGAIN       

开发者_如何学C     over :   MOV AH,4C
              INT 21H

  CODE ENDS  
END START  


You are not printing out an answer, just exiting with 0 as your return value. You will need to add more system calls to print out the value in CL after your loop.


All your code segment is doing is counting them, you still need to output the value once you're done.

Provided the count is less than 10, you can use the simple:

over:  push  cx           ; transfer cl to dl for int21/ah=2.
       pop   dx
       add   dx, 30h      ; convert number to character.
       mov   ah, 02h      ; prints the character in dl.
       int   21h
       mov   ah, 4ch      ; exit.
       int   21h

In terms of printing strings, you can use int21,ah=9. Ralf Brown's interrupt list is an excellent resource for this sort of stuff.

For outputting numbers greater than 9, you will have to do the normal division/modulo trickery.

Some code to do that can be found here, but you can probably get away with something like this com file:

0100            mov   si, numlist       ; get the list base.
0103            mov   cl, 0             ; counter initially zero.

0105 loop1:     mov   al, 0             ; stop on sentinel of zero.
0107            cmp   al, [si]
0109            je    pr_pre
010B            inc   si                ; otherwise advance and increase count.
010C            inc   cl
010E            jmp   loop1             ; and go back for more.

0110 pr_pre:    mov   ah, 09            ; output the initial text.
0112            mov   dx, pretext
0115            int   21

0117 hundreds:  mov   dl, 30            ; process hundreds digit, initially '0'.
0119            jmp   skip2             ; skip initial.
011B loop2:     inc   dl                ; add 1 to count, sub 100 from tally
011D            sub   cl, 64
0120 skip2:     cmp   cl, 64
0123            jge   loop2             ; continue until < 100
0125            mov   ah, 02            ; print character.
0127            int   21

0129 tens:      mov   dl, 30            ; process tens digit, same as hundreds.
012B            jmp   skip3
012D loop3:     inc   dl
012F            sub   cl, 0a            ; except use 10 rather than 100
0132 skip3:     cmp   cl, 0a
0135            jge   loop3
0137            mov   ah, 02
0139            int   21

013B units:     mov   dl, cl            ; what's left is units.
013D            add   dl, 30            ; just add '0' and print.
0140            mov   ah, 02
0142            int   21

0144 pr_post:   mov   ah, 09            ; the print CR/LF.
0146            mov   dx, 15e
0149            int   21

014B exit:      mov   ah, 4c            ; and exit.
014D            int   21

014F pretext:   db    "The count is: $"
015E posttxt:   db    0a, 0d, "$"
0161 numlist:   db    1,2,3,4,5,6,7,8,9
016a            db    10,11,12,13,14,0
0

精彩评论

暂无评论...
验证码 换一张
取 消