Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly 8085 Help

Status
Not open for further replies.

JonRoss12

New Member
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
 
Status
Not open for further replies.

Latest threads

Back
Top