Answer to Question #285653 in Assembler for TayyTayyy

Question #285653

Write an 8086 assembly language program to push the following values on stack 450, 0, 487, 101, 500, 0, 359, 0, 458 Now write a code to delete the items having quantity zero and update the stack.


1
Expert's answer
2022-01-09T02:21:11-0500
.stack 16h
DATA SEGMENT

DATA ENDS

CODE SEGMENT
START:
    MOV AX,DATA
    MOV DS,AX    
    MOV ES,AX
 
     push bp     ; save on stack the base pointer
     
;  to push the 9 values on stack
    push 450
    push 0
    push 487
    push 101
    push 500
    push 0h
    push 359
    push 0h
    push 458

    mov cx,9     ; counter
    mov bp, sp   ; BP - Itis offset address relative to stack segment.

    add sp, 2
    add bp ,2
       
  begining:
    pop ax       ; pop from stack
    dec cx       ; counter--
    cmp cx,0     ; last value?
    je exit
    
      cmp ax,0    ; value == 0?
    je next

    mov [bp],ax     ; store non-null value on the stack
    add bp,2        ;next save address
    jmp begining
    
next:
    jmp begining  
       
 exit:    
     pop bp    ; restore bp
     
   MOV AH,1            ; Waiting for a key press
   INT 16H    

EXIT_PROG:            ; Program is terminated
     MOV AH,4CH
     INT 21H

CODE ENDS
END START




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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS