Hack Forums
[Help] Having a little trouble with emu8086 - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Having a little trouble with emu8086 (/showthread.php?tid=3831396)



Having a little trouble with emu8086 - camrymps - Oct 28, 2013

I am having a little trouble with an assignment that I have to complete in emu8086. What I have to do is, as the teacher states:

Quote:Write two lines to push a byte stored in dh on to myStack.
Write two lines to pop a byte stored in myStack into dl.


Here is the code that I have so far:

Code
;kevin o'keeffe

org 100h
jmp START

myStack db 8 dup (?)    
_myStackSize equ 8        

START:
mov si, _myStackSize    ;si holds size of myStack

mov dh, '1'                ;move '1' (which is ascii 31) to dh
mov cx,5                ;Wish to execute loop body 5 times (must use cx with loop command)
PUSH_LOOP:
    
    ;push myStack
    [color=#FF0000]mov si, 0h    [/color]            ;change si so myStack[si] is the new top of myStack
    [color=#FF0000]mov dh, myStack(si)[/color]                    ;mov dh to the new top of myStack
    
    inc dh                
    loop PUSH_LOOP        ;dec cx        jnz PUSH_LOOP

mov cx,5          
POP_LOOP:                ;Wish to execute loop body 5 times (must use cx with loop command)
    
    ;pop myStack
    ;[color=#FF0000]???    [/color]                ;mov (ie copy) the top element of myStack to dl
    ;[color=#FF0000]???    [/color]                ;change si so myStack[si] is the new top of myStack
    
    mov ah, 02h            ;Send rv
    int 21h                ;to screen
    
    ;Advance screen to new print line
    mov ah, 02h
    mov dl,0Dh
    int 21h
    mov dl,0Ah
    int 21h
    loop POP_LOOP    ;dec cx        jnz PUSH_LOOP      

ret

The four lines in red are what I have to change/make. Please help!


* - Cybride - Oct 29, 2013

Why are you trying to use absolute values here?
Code
PUSH_LOOP:
    dec si
    mov myStack[si], dh

Code
POP_LOOP:
   mov dl, myStack[si]
   inc si