What causes this infinite loop?



I hope y'all don't mind my frequent questions, so here's another...

In emu8086 I wanted to see what would happen if I left some data on the
stack and exit the program with the following:

;begin
mov ax, 0ffh ; Is it a good practice to start all hex numbers with a
zero?
push ax
;pop ax ; If I pop ax, the program exits and all appears aok.
ret
end
;end

I thought the program would stop when IP reached ffffh, but it started
over at 0 and kept chugging along. The emulator jumps to "ret" and
starts executing, "ADD [BX + SI], AL". The memory locations start
incrementing filling with NULLs that look like this, "0E711: 00 000
NULL" (memory hex decimal ascii). BX and SI are both "0000", so the
code is trying put ffh into offset zero. IIRC, each zero offset of
every assembly program I have run has always been NULL (not sure why,
but it's probably important). So, since the code is trying to put a
value into what is probably an important memory location, there is a
disturbance in the force.

If I "pop ax" after the push, the program exits at "10F00: F4 244
<ascii character>" (memory hex decimal ascii) with the next memory
location being "10F01: 00 000 NULL" (memory hex decimal ascii) and
associated with the instruction "ADD [BX + SI], AL".

Is it always the case that a program with "blow up" if something is
left on the stack?
--
Sam

.



Relevant Pages

  • Re: perf_copy_attr pointer arithmetic weirdness
    ... checks that all bytes trailing a struct are zero. ... an iterating pointer by sizeofrather than 1. ... doesn't seem to take any boundary conditions into account which is probably not ... ret = get_user; ...
    (Linux-Kernel)
  • [PATCH 133/148] include/asm-x86/uaccess_32.h: checkpatch cleanups - formatting only
    ... * Returns zero on success, ... the variable @x is set to zero. ... return ret; ...
    (Linux-Kernel)
  • Re: dead threads
    ... mostly only one leak. ... UINT ret = 0; ... iActiveThreads is zero after he has done his work? ...
    (microsoft.public.vc.mfc)
  • Re: select(0, ..) is valid ?
    ... ret = -ENOMEM; ... avoids kmalloc by using a buffer on the stack for small allocations (and ... Or is SLUB going to be so efficient that doing so is a waste of time? ... I don't think using the zero page that way would be at all safe: ...
    (Linux-Kernel)
  • perf_copy_attr pointer arithmetic weirdness
    ... checks that all bytes trailing a struct are zero. ... Since it increments ... an iterating pointer by sizeofrather than 1. ... ret = get_user; ...
    (Linux-Kernel)