Thread: Creating push & pop functions... decrementing/tracking?

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    98
    Quote Originally Posted by lolguy View Post
    i Thought push is assembly ?
    It is, that's why I need to create a push & pop function by hand since I'm working in C

  2. #17
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by lolguy View Post
    i Thought push is assembly ?
    It is called push in most assembly languages, but you are using C.
    I don't think C has a 'push' as far as I am aware.

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    when you using asm with c you do __asm{
    or can you use push directly with it ?

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by lolguy View Post
    when you using asm with c you do __asm{
    or can you use push directly with it ?
    The odds that we actually want to push on the system stack is very very very very very small. We want our own stack.

  5. #20
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Z80 assembler stack operations.
    Unfortunately it is abit more complicated as the registers are paired
    so you push two 8 bit ints to store two paired 8 bit registers.
    Also it is 'upside down' the 'top' of the stack is high and as you push stuff
    onto it it is stored at lower memory locations.

    Code:
    PUSH 	B 	PUSH 	BC 	C5 	(SP-2) <- C; (SP-1) <- B; SP <- SP - 2
    PUSH 	D 	PUSH 	DE 	D5 	(SP-2) <- E; (SP-1) <- D; SP <- SP - 2
    PUSH 	H 	PUSH 	HL 	E5 	(SP-2) <- L; (SP-1) <- H; SP <- SP - 2
    PUSH 	PSW 	PUSH 	AF 	F5 	(SP-2) <- Flags; (SP-1) <- A; SP <- SP - 2
    ---		PUSH 	IX 	DDE5 	(SP-2) <- IXl; (SP-1) <- IXh; SP <- SP - 2
    ---		PUSH 	IY 	FDE5 	(SP-2) <- IYl; (SP-1) <- IYh; SP <- SP - 2
    POP 	B 	POP 	BC 	C1 	B <- (SP+1); C <- (SP); SP <- SP + 2
    POP 	D 	POP 	DE 	D1 	D <- (SP+1); E <- (SP); SP <- SP + 2
    POP 	H 	POP 	HL 	E1 	H <- (SP+1); L <- (SP); SP <- SP + 2
    POP 	PSW 	POP 	AF 	F1 	A <- (SP+1); Flags <- (SP); SP <- SP + 2

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It is, but it's been part of C since Turbo C/C++ 1.01, that I know of.

  7. #22
    Registered User
    Join Date
    Dec 2008
    Posts
    15
    Quote Originally Posted by lolguy View Post
    i Thought push is assembly ?
    It is, except that here we are using terms that are similar thing only implementing them with C.

  8. #23
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by lolguy View Post
    i Thought push is assembly ?

    Yes you can call it what ever you like, call it shove(x) if you like and then pull(x), it's just
    an arbitary name of a function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating and using functions
    By moy18 in forum C Programming
    Replies: 2
    Last Post: 11-01-2007, 04:26 AM
  2. Assembly Tutorials
    By JoshR in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 06-11-2005, 09:56 AM
  3. Creating Functions that use Format control Strings
    By tzuchan in forum C Programming
    Replies: 6
    Last Post: 03-29-2004, 12:50 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Replies: 5
    Last Post: 09-17-2001, 06:18 AM