8085 Debugging help

Discussion in 'Assembly Language Programming (ALP) Forum' started by jonross, Jan 6, 2015.

  1. jonross

    jonross New Member

    Joined:
    Jan 6, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I was wondering if anyone could help me with debugging this program? It's not printing out the way I expected it to, and I could use another set of eyes to help me figure out what's wrong with it. It's supposed to print out 3 vertical lines of X's of a length determined by the user, but isn't printing out the lines correctly.

    Thanks!

    Code:
       bdos      equ    5            ; CP/M function call address
       boot      equ    0            ; address to get back to CP/M
       conin     equ    1            ; keyboard read function number
       conout    equ    2            ; console output function number
       sprint    equ    9            ; string print function number
       cr        equ    0Dh          ; value of ASCII code of <CR>
       lf        equ    0Ah          ; value of ASCII code of line feed
    
    ;
    	org 0100h	
    	lxi sp,sp0	;init stack
    	mvi c, sprint
    	lxi d, title	;calls first part of title at title
    	call bdos
    	mvi c, sprint
    	lxi d, title2	;calls second part of title
    	call bdos
    	call lines
    	call print
    	mvi c, sprint
    	lxi d,endgraph
    	call bdos
    	lxi d,endmess
    	call bdos
    	jmp boot
    
    
    
    
    
    ;lines subroutine
    lines:	mvi c, sprint
    	lxi d, line1	;prompts for 1st length
    	call bdos							;1=b
    	mvi c, conin
    	call bdos
    	mov b,a		;moves 1st length into b
    	
    	mvi c, sprint
    	lxi d, line2	;prompts for 2nd length
    	call bdos
    	mvi c, conin							;2=d
    	call bdos
    	mov d,a		;moves 2nd length into d
    	push d
    
    	mvi c, sprint
    	lxi d, line3	;prompts for 3rd length
    	call bdos
    	mvi c, conin							;3=h
    	call bdos
    	mov h,a		;moves 3rd length into h
    	pop d
    	ret
    
    
    
    ;print subroutine
    print:	mvi c,conout
    	push d		;keeps d from being overwritten
    	lxi d,enter	;puts in an enter
    	call bdos
    	pop d	
    	mov a,b		;1st len to a
    	cmp d		;1st-2nd
    	jm sec		;2nd>=1st
    	jz sec
    	cmp h		;1st-3rd
    	jm threeh	;3rd>=1st>2nd, otherwise is 1st>2nd>3rd
    	jz threeh
    	jmp oneh
    
    sec:	mov a,d
    	cmp h		;2nd-3rd
    	jm threeh	;3rd>=2nd>=1st, otherwise 2nd is highest
    	jz threeh
    	jmp twoh
    
    oneh:	mov a,b
    reponeh:
    	cpi 0
    	rz		;ends prog once gets to end of 1s
    	push d		;keeps d from being overwritten
    	lxi d,xchar	;puts in an x
    	call bdos	
    	mvi c,conout
    	lxi d,fourspace	;puts in 4 spaces
    	call bdos
    	pop d	
    	call bdos
    	cmp d		;1st-2nd
    	jp twospace	;puts in space
    	push d		;keeps d from being overwritten
    	lxi d,xchar	;puts in an x
    	call bdos	
    two:	lxi d,fourspace	;puts in 4 spaces
    	call bdos	
    	call bdos
    	cmp h		;1st-3rd
    	jp threespace	;puts in space
    	lxi d,xchar	;puts in an x
    	call bdos
    three:	sui 1		;decriments counter
    	lxi d,enter	;puts in an enter
    	call bdos
    	pop d	
    	jmp reponeh
    
    twospace:
    	push d		;keeps d from being overwritten
    	lxi d,space	;puts in a space
    	call bdos	
    	jmp two
    
    threespace:
    	lxi d,space	;puts in a space
    	call bdos	
    	jmp three	
    
    
    twoh:	mov a,d
    reptwoh:
    	cpi 0
    	rz
    	cmp b		;2nd-1st	
    	jp twohonespace	;puts in space
    	lxi d,xchar	;puts in an x
    	call bdos	
    twohone:
    	lxi d,fourspace	;puts in 4 spaces
    	call bdos
    	lxi d,xchar	;puts in an x
    	call bdos
    	lxi d,fourspace	;puts in 4 spaces
    	call bdos
    	call bdos
    	cmp h		;2nd-3rd
    	jp twohthreespace	;puts in space
    	lxi d,xchar	;puts in an x
    	call bdos
    twohthree:
    	sui 1		;decriments counter
    	lxi d,enter	;puts in an enter
    	call bdos
    	jmp reptwoh
    
    twohonespace:
    	lxi d,space	;puts in a space
    	call bdos
    	jmp twohone
    
    twohthreespace:	
    	lxi d,space	;puts in a space
    	call bdos
    	jmp twohthree
    
    
    threeh:	mov a, h
    repthreeh:
    	cpi 0
    	rz
    	cmp b		;3rd-1st
    	jp threehonespace	;puts in space
    	push d		;keeps d from being overwritten
    	lxi d,xchar	;puts in an x
    	call bdos
    threehone:
    	lxi d,fourspace	;puts in 4 spaces
    	call bdos
    	pop d	
    	call bdos
    	cmp d		;3rd-2nd
    	jp threehtwospace
    	push d		;keeps d from being overwritten
    	lxi d,xchar	;puts in an x
    	call bdos	
    threehtwo:
    	lxi d,fourspace	;puts in 4 spaces
    	call bdos
    	lxi d,xchar	;puts in an x
    	call bdos	
    	sui 1		;decriments counter
    	lxi d,enter	;puts in an enter
    	call bdos
    	pop d	
    	jmp repthreeh
    
    threehonespace:
    	lxi d,space	;puts in a space
    	call bdos	
    	jmp threehone
    
    threehtwospace:
    	push d		;keeps d from being overwritten
    	lxi d,space	;puts in a space
    	call bdos	
    	jmp threehtwo	
    	
    
    
    
    
    title: db 'Three Lines$'
    title2: db lf,cr, 'I will print three lines of given lengths$'
    line1: db lf,cr,'Length of first line: $'
    line2: db lf,cr,'Length of second line: $'
    line3: db lf,cr,'Length of third line: $'
    xchar: db 'X    $'
    enter: db lf,cr, '$'
    fourspace: db '    $'
    space: db '     $'
    endgraph: db lf,cr, '1    2    3$'
    endmess: db lf,cr,'Thank you for using the Three Lines program$'
    
    
    	ds 20		;reserve for stack
       	sp0 equ $	;stack pointer address
    	end
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Can you give a couple of examples of the input you give and the output you got? It's easier to see where a program is going wrong with some output.
     
  3. jonross

    jonross New Member

    Joined:
    Jan 6, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Right now if I put in something like
    Code:
    Length of first line: 6
    Length of second line: 4
    Length of third line: 2
    I just get

    Code:
    1    2    3
    Thank you for using the Three Lines Program
    as output. But it should be giving me something more like

    Code:
    X        
    X        
    X    X
    X    X
    X    X    X
    X    X    X
    1    2    3
    Thank you for using the Three Lines Program
    I can't quite figure out where the program stops working, as the registers have the proper numbers in them.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Could you show the complete unedited output please?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice