1

using tasm/tlink/dosbox in notepad++

want: how do i fix 2 digit divide to 2 digits and when if the quotient or remainder answer is also 2 digits? and also what is the possible logic?

my flow is: the flow I made was first I took the first digit of the first number or dividend then I multiplied by 10 to be and I added to the second digit the same as the second number or divisor so that it would be 2 digits in the register after that I'll divide them both.

My Code in notepad++:

.model small
.stack 100h
.data
            d0  db 0dh,0ah,"Base 03$"
            d1  db 0dh,0ah,"Enter Dividend    : $"  ;string
            d2  db 0dh,0ah,"Enter Divisor     : $"
            d3  db 0dh,0ah,"Display Quotient  : $"
            d4  db 0dh,0ah,"Display Remainder  : $"
            
.code
main proc   ;main program here
            
            mov ax,@data                ;initialize ds
            mov ds,ax
            
            Div1:
                mov ah,09h
                lea dx,d0
                int 21h
                
                lea dx, d1
                int 21h
                mov ah,01h
                int 21h                     ;1st Digit
                
                mov ch,al
                
                mov ah,01h
                int 21h                     ;2nd Digit
        
                mov cl,al
                
                or cx,3030h
                
                mov al,ch
                mov bl,10h
                mul bl                      ;02*10 = 20
                
                mov bh,al
                add bh,cl                   ;dividend
        
            Div2:
                mov ah,09h
                lea dx, d2
                int 21h
                mov ah,01h
                int 21h                     ;1st Digit
                
                mov ch,al
                
                mov ah,01h
                int 21h                     ;2nd Digit
        
                mov cl,al
                
                or cx,3030h
                
                mov al,ch
                mul bl                      
                mov dh,al
                add dh,cl                   ;divisor
                
                mov ah,00h
                mov al,bh
                aad
                div dh
                mov cx,ax
                or  cx,3030h
                
                mov ah,09h
                lea dx, d3
                int 21h
                mov ah,02h
                mov dl,cl
                int 21h
                
                mov ah,09h
                lea dx, d4
                int 21h
                mov ah,02h
                mov dl,ch
                int 21h
                
                mov ah,4Ch                  ;end here
                int 21h
            
main endp
end main    

Output:

enter image description here

Want Output:

Enter Dividend     : 22
Enter Divisor      : 02
Display Quotient   : 02
Display Remainder  : 00

proj

Enter Dividend     : 21
Enter Divisor      : 02
Display Quotient   : 10
Display Remainder  : 01

proj

Enter Dividend     : 21
Enter Divisor      : 11
Display Quotient   : 01
Display Remainder  : 10

like this calculation but the only i need is the quotient and remainder.

enter image description here

2 Answers2

2

Are you sure about "Want output" ?

Enter Dividend     : 22   <<< 8d
Enter Divisor      : 02   <<< 2d
Display Quotient   : 02   ??? 4d == 11
Display Remainder  : 00   <<< 0d

or cx,3030h does nothing to your code because those bits will already have been set, they're part of the ASCII codes from 48 to 50. For conversion purposes you would normally use sub cx,3030h.

Next your multiplication with 10h (16 in decimal) is trying to turn the input into packed BCD (binary coded digits) format. Later the code will use the aad instruction that operates on unpacked BCD and importantly uses 10 as its number base where your program is going for number base 3.

You seem to expect a 2-digit output for both quotient and remainder. Then just printing 2 characters from CL and CH is not enough.

To do

mov ah,01h
int 21h                     ;1st Digit
mov ch,al
mov ah,01h
int 21h                     ;2nd Digit
mov cl,al
sub cx,3030h
mov al, 3
mul ch
add al, cl
mov bh,al                   ;dividend = (D1 * 3) + D2

Similarly for the divisor, but put it in BL

mov ah, 0
mov al, bh    ; Dividend in BH
div bl        ; Divisor in BL
mov cx, ax    ; Quotient in CL, Remainder in CH

Ready to print. See my answer I need to show 3 digit answer Using tasm/tlink/dosbox in notepad++

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • yes I'm sure of the output I want because it's a 2 digit form of divide so if you divide the answer should also be 2 digits and it needs to be based on 3 – Devil Blacklist Jun 02 '22 at 11:10
  • i get what you code here but it will base in 03 si if the divisor get quotient value they need to multiply then convert in base 03... and then minus to the dividend which is i do not know how do i put the logic... – Devil Blacklist Jun 02 '22 at 16:32
  • 1
    @DevilBlacklist: This is base 3? Your question and sample input/output didn't mention that until your edit a few minutes ago. (except for one string in your code. The actual code treats the input as base 10h, i.e. base 16, but without supporting digits a-f, so anyone reading your code would assume that "base 3" string was left over from something else.) I thought yesterday this sample output looked familiar from a previous question about a base other than 10, and was going to edit vitsoft's answer to change the use of "decimal" point, but then rechecked this question and saw no sign of base 3 – Peter Cordes Jun 02 '22 at 17:03
  • My bad I think they get the bases I need and I'm sorry we were only taught the most basic assembly handle instructions so I can't enter the depth like the bases especially in the division so I want to be clear on how to enter the divide solving of the calculation there in the last picture I edited. @Peter Cordes – Devil Blacklist Jun 02 '22 at 17:12
  • @DevilBlacklist: You don't need different instructions, you can still multiply and divide, but with different constants: by 3 instead of 10 or 16. (You do have to fix the ASCII -> integer conversion part, though: either AND to mask away the high bits, or use SUB on the expected high bits). If you're just copy/pasting instructions from other code without understanding what it does, there's your problem. Think through the algorithm you want to implement, or write it in C or some other language you know and actually get it working, before implementing in asm. – Peter Cordes Jun 02 '22 at 17:27
  • @Peter Cordes: I didn't just copy and paste the instructions code that was given, I always visualized on paper how the flow of the code works. – Devil Blacklist Jun 02 '22 at 17:33
  • @DevilBlacklist: Ok, good, then you do realize you were doing `digit1 * 10 + digit2`, and could write that in C to try it out, and realize that you're not getting the number represented by that 2-digit base3 string. (2*3 + 2*1 = 5(decimal), which would be represented as a binary `int` as `0b101` in case you care about that). I guess being able to check the resulting number requires knowing how to do base conversion / place-value stuff in the first place, though, so probably that's what you're missing. A web search for `place value base conversion` brought up some math hits. – Peter Cordes Jun 02 '22 at 17:41
1

Your algorithm for conversion is confused:

first I took the first digit of the first number or dividend then I multiplied by 10 to be and I added to the second digit

In fact you have multiplied the first digit by 16 because of mov bl,10h. See also questions 8086 simple decimal addition from user input or How to convert an ASCII char to a decimal representation?. Or use some more general method to how to convert input string with more than two decimal numbers to a binary value. See the macro LodD for inspiration.

What you need is Turbo Debugger which allows to execute you program instruction by instruction and watch if the registers change as expected.

vitsoft
  • 5,515
  • 1
  • 18
  • 31