about summary refs log blame commit diff stats
path: root/101stack_allocate.subx
blob: 02ad84f2325652534c8cface81649063ce880bc7 (plain) (tree)





























































                                                                               
# A function which pushes n zeros on the stack.
# Not really useful to call manually.
# The Mu compiler uses it when defining arrays on the stack.

== code

#? Entry:
#?     # . prologue
#?     89/<- %ebp 4/r32/esp
#?     #
#?     68/push 0xfcfdfeff/imm32
#?     b8/copy-to-eax 0x34353637/imm32
#? $dump-stack0:
#?     (push-n-zero-bytes 4)
#?     68/push 0x20/imm32
#? $dump-stack9:
#?     b8/copy-to-eax 1/imm32/exit
#?     cd/syscall 0x80/imm8

# This is not a regular function, so it won't be idiomatic.
# Registers must be properly restored.
# Registers can be spilled, but that modifies the stack and needs to be
# cleaned up.

# Overhead:
#   62 + n*6 instructions to push n bytes.
# If we just emitted code to push n zeroes, it would be:
#   5 bytes for 4 zero bytes, so 1.25 bytes per zero. And that's not even
#   instructions.
# But on the other hand it would destroy the instruction cache, where this
# approach requires 15 instructions, fixed.

# n must be positive
push-n-zero-bytes:  # n: int
$push-n-zero-bytes:prologue:
    89/<- *Push-n-zero-bytes-ebp 5/r32/ebp  # spill ebp without affecting stack
    89/<- %ebp 4/r32/esp
$push-n-zero-bytes:copy-ra:
    # -- esp = ebp
    50/push-eax
    # -- esp+8 = ebp+4
    # -- esp+4 = ebp
    8b/-> *(esp+4) 0/r32/eax
    2b/subtract *(ebp+4) 4/r32/esp
    # -- esp+4+n = ebp
    89/<- *(esp+4) 0/r32/eax
    58/pop-to-eax
    # -- esp+n = ebp
$push-n-zero-bytes:bulk-cleaning:
    89/<- *Push-n-zero-bytes-esp 4/r32/esp
    81 0/subop/add *Push-n-zero-bytes-esp 4/imm32
    81 0/subop/add *(ebp+4) 4/imm32
    (zero-out *Push-n-zero-bytes-esp *(ebp+4))  # n+4
$push-n-zero-bytes:epilogue:
    8b/-> *Push-n-zero-bytes-ebp 5/r32/ebp  # restore spill
    c3/return

== data
Push-n-zero-bytes-ebp:  # (addr int)
  0/imm32
Push-n-zero-bytes-esp:  # (addr int)
  0/imm32
=bold_yellow mention=bold_green trigger=bold_green typing=bold_yellow gone=bold_red error=bold_red roominfo=bold_yellow roommention=bold_green roommention.term=bold_green roomtrigger=bold_green roomtrigger.term=bold_green me=bold_cyan them=bold_magenta roster.header=bold_magenta roster.chat=white roster.online=green roster.away=cyan roster.xa=cyan roster.dnd=red roster.offline=bold_blue roster.chat.active=white roster.online.active=green roster.away.active=cyan roster.xa.active=cyan roster.dnd.active=red roster.offline.active=bold_blue roster.chat.unread=bold_white roster.online.unread=bold_green roster.away.unread=bold_cyan roster.xa.unread=bold_cyan roster.dnd.unread=bold_red roster.offline.unread=bold_blue roster.room=bold_red roster.room.unread=bold_magenta roster.room.mention=bold_magenta roster.room.trigger=bold_magenta occupants.header=bold_magenta receipt.sent=bold_blue [ui] beep=false flash=false splash=true wrap=true time.console=%H:%M:%S time.chat=%d/%m/%y %H:%M:%S time.muc=%d/%m/%y %H:%M:%S time.mucconfig=off time.private=%d/%m/%y %H:%M:%S time.xml=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=true presence=true intype=true enc.warn=true resource.title=true resource.message=true statuses.console=all statuses.chat=all statuses.muc=none roster=true roster.offline=true roster.empty=false roster.by=group roster.order=presence roster.unread=before roster.count=true roster.priority=false roster.size=25 roster.wrap=true roster.header.char=@ roster.contact.indent=1 roster.resource=true roster.resource.char=/ roster.resource.indent=1 roster.resource.join=true roster.presence=true roster.presence.indent=-1 roster.status=true roster.contacts=true roster.rooms=true roster.rooms.order=name roster.rooms.unread=before roster.rooms.pos=last occupants=true occupants.size=15 occupants.jid=false wins.autotidy=true otr.char=@ pgp.char=% tls.show=true console.muc=first titlebar.position=1 mainwin.position=2 statusbar.position=3 inputwin.position=4