丑小鸭告诉我们一个什么道理| sany是什么牌子| 驴打滚是什么| 羊膜束带是什么意思| 夏季种什么菜| 梦到自己怀孕了是什么预兆| 烫伤用什么药膏| 空心菜什么人不能吃| 牙冠是什么| 为什么订婚后容易分手| 医学检验技术是干什么的| h代表什么意思| 什么的妈妈| 授人以鱼不如授人以渔什么意思| 踮脚尖有什么好处| p.a.是什么意思| 钟点房什么意思| 人面桃花相映红是什么意思| sin是什么边比什么边| 身份证照片穿什么颜色衣服| 什么什么不周| 方解石玉是什么玉| 眼带用什么方法消除| 妇科臭氧治疗是什么| 纯磨玻璃结节是什么意思| 姜水什么时候喝最好| 月亮星座是什么| 石花菜是什么植物| 物美价廉是什么意思| tbc是什么意思| 月经推后是什么原因引起| 鳑鲏吃什么| 出冷汗是什么原因| 梦见长白头发是什么意思| 肚脐眼上方是什么器官| igg是什么意思| 尿胆原是什么| 土家族是什么族| 血小板高有什么危害| 火腿肠是什么做的| 9月9日是什么星座| 麦字五行属什么| 痛风用什么消炎药最好| 排卵试纸一深一浅说明什么| 支原体是什么病| 小腹凸起是什么原因| 6.20什么星座| 腰肌劳损是什么症状| 称中药的小秤叫什么| 牙虫是什么样的图片| 善根是什么意思| 好机车是什么意思| 104岁属什么生肖| 炖羊肉都放什么调料| 什么叫国学| 口臭严重吃什么药好得快| 薷是什么意思| xxoo是什么意思| 小孩发育迟缓是什么原因造成的| 那个叫什么| 等不到天黑烟火不会太完美什么歌| 侄女叫我什么| 小便多吃什么药好| 1985年属牛是什么命| 阳光明媚下一句接什么| 澳大利亚有什么特产| 血小板低有什么症状| 潮吹是什么感觉| 龟头上有小红点是什么| 山花对什么| 富氢水是什么| 一纸空文是什么意思| 前列腺增生吃什么药| 耐受性是什么意思| 安全监察是一种带有什么的监督| 民营企业和私营企业有什么区别| 胃疼是什么症状| 老梗是什么意思| 脚底发凉是什么原因| lam是什么意思| 怀孕了吃什么药能流掉| 舌头有裂纹什么原因| 什么样的大便是正常的| 尿黄是什么原因| 吃什么对肠道好| 213什么星座| pick什么意思| 怀孕脸上长痘痘是什么原因| 阴道排气是什么原因| 超敏c反应蛋白偏高说明什么| 榴莲什么味道| 舌头紫红色是什么原因| 什么是扁平足| 免疫球蛋白是什么东西| 安大爷是什么意思| 梦见掉牙齿是什么征兆| 右肺中叶索条什么意思| 色痨是什么病| 李世民是什么生肖| 黑枸杞和红枸杞有什么区别| 孕期阴道炎可以用什么药| 吃什么可以祛痘排毒| 碱性水是什么水| 1964年属什么的| 太阳是什么星| 吃什么东西养胃最有效| 桃字五行属什么| 郁郁寡欢是什么意思| 婴儿坐飞机需要什么证件| 武火是什么意思| 吐槽是什么意思| 红色加绿色等于什么颜色| 银针茶属于什么茶| 牛百叶是什么| 阿司匹林肠溶片什么时候吃| 12月22日什么星座| 皮肤发白一块一块的是什么病| 冰粉是什么做的| 下午17点是什么时辰| 婴儿眉毛上黄痂是什么| 尿常规挂什么科| 舌吻是什么意思| 额头老出汗是什么原因| 马镫什么时候发明的| 遗忘的遗是什么意思| 石膏的主要成分是什么| 折耳根什么味道| 嗓子痛什么原因| 孕妇适合喝什么牛奶| 湿吻是什么意思| 7月29号是什么星座| 淋巴结什么意思| 发烧吃什么水果好| 毕业是什么意思| 621什么星座| 金骏眉是什么茶| eb病毒抗体阳性是什么意思| 什么时候绝经| 压测是什么意思| 荔枝和什么吃会中毒| 叶凡为什么要找荒天帝| 脾胃不好能吃什么水果| 花青素有什么作用| 阳虚吃什么中成药| 黄瓜为什么是绿色的| 出水痘吃什么药| 两个人可以玩什么游戏| 为什么不能下午看病人| 待产包需要准备什么| 音欠读什么| 尿味重是什么原因| 扩张是什么意思| 皇太极叫什么名字| 晒伤用什么药膏| 喝酒容易醉是什么原因| 女人腿肿应该检查什么| 游离是什么意思| 黄明胶是什么| r级电影是什么意思| 芃字五行属什么| 环球中心有什么好玩的| 考试前吃什么能让大脑发挥最佳| 天宫是什么意思| 长期湿热会引起什么病| 拔完罐需要注意什么| 造影检查是什么意思| 心机血缺血吃什么药最好| 同学过生日送什么礼物好| 苦瓜和什么搭配最好| 反响是什么意思| 素鸡是什么| cpk是什么意思| 菲薄是什么意思| 威士忌是用什么酿造的| 癫狂是什么意思| 山花对什么| 血压高吃什么水果| 榴莲树长什么样| 女人味是什么| 手臂酸痛什么原因| 怀孕拉肚子吃什么药| 仔细的什么| 两栖动物是什么意思| 你是电你是光是什么歌| 9月14号什么星座| live什么意思| 夏季喝什么茶| 卵巢囊肿吃什么食物好| swag什么意思| 股票xd开头是什么意思| amy什么意思| 雨云是什么字| 为什么胸闷一吃丹参滴丸就好| 一面之词是什么意思| 青葱岁月下一句是什么| 大暑是什么意思| 桃花是指什么生肖| 心率低吃什么药好| 喝什么汤下奶最快最多| 亨廷顿舞蹈症是什么病| 慧五行属什么| 腰疼不能弯腰是什么原因引起的| peaches是什么意思| 椎间盘变性是什么意思| 转氨酶升高有什么症状| 双重所有格是什么意思| 炀是什么意思| 什么是血铅| 红枣为什么要去核煮| 带子是什么海鲜| 一直打嗝是什么问题| 什么是肺大泡| 椰子和椰青有什么区别| 慧眼识珠是什么意思| 出院小结是什么| 不解大便是什么原因| 端午节干什么| 受用是什么意思| 周瑜是什么样的人| 兔子能吃什么水果| 云南白药治什么| 也是什么意思| 为什么会无缘无故长痣| 急性肠胃炎打什么点滴| 钾高是什么原因引起的| 带环了月经推迟不来什么原因| 通五行属什么| px是什么意思| 做梦房子倒塌什么预兆| 肠胃炎引起的发烧吃什么药| 菱角什么时候上市| 724是什么意思| 立牌坊是什么意思| 拔智齿后吃什么恢复快| 5个月宝宝可以吃什么水果| 人生海海是什么意思| 劲旅是什么意思| 肝火郁结是什么症状| 运费险是什么意思| 宫颈管积液什么意思| 吃什么丰胸效果最好最快| e-mail什么意思| 什么减肥药好使| 转氨酶偏高是什么原因| 为什么耳朵后面会臭| 一个木一个号念什么| 皲裂是什么意思| 陶白白是什么星座| tcl什么牌子| ug是什么单位| 纣王叫什么名字| 化学性肝损伤是什么意思| 786是什么意思| 滞留是什么意思| 小孩说话不清楚挂什么科| 双鱼座的幸运色是什么| 碱性土壤适合种植什么| 鹅蛋吃了有什么好处| 风热感冒吃什么食物| 什么叫理疗| 女人出虚汗是什么原因引起的| 憨厚是什么意思| 三月六号是什么星座| pacu是什么意思| 百度Jump to content

三明市举行全国侵权盗版及非法出版物集中...

From Wikipedia, the free encyclopedia
百度 于正提到,明者因时而变,传统文化在今天的发展要尊重年轻化趋势,以年轻人更容易接受的叙事方式去呈现。

In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return a result.[1] When some code calls a function, design choices have been taken for where and how parameters are passed to that function, and where and how results are returned from that function, with these transfers typically done via certain registers or within a stack frame on the call stack. There are design choices for how the tasks of preparing for a function call and restoring the environment after the function has completed are divided between the caller and the callee. Some calling convention specifies the way every function should get called. The correct calling convention should be used for every function call, to allow the correct and reliable execution of the whole program using these functions.

Introduction

[edit]

Calling conventions are usually considered part of the application binary interface (ABI). They may be considered a contract between the caller and the called function.[1]

[edit]

The names or meanings of the parameters and return values are defined in the application programming interface (API, as opposed to ABI), which is a separate though related concept to ABI and calling convention. The names of members within passed structures and objects would also be considered part of the API, and not ABI. Sometimes APIs do include keywords to specify the calling convention for functions.

Calling conventions do not typically include information on handling lifespan of dynamically allocated structures and objects. Other supplementary documentation may state where the responsibility for freeing up allocated memory lies.

Calling conventions are unlikely to specify the layout of items within structures and objects, such as byte ordering or structure packing.

For some languages, the calling convention includes details of error or exception handling, (e.g. Go, Java) and for others, it does not (e.g. C++).

For Remote procedure calls, there is an analogous concept called Marshalling.

Calling conventions may be related to a particular programming language's evaluation strategy, but most often are not considered part of it (or vice versa), as the evaluation strategy is usually defined on a higher abstraction level and seen as a part of the language rather than as a low-level implementation detail of a particular language's compiler.

Different calling conventions

[edit]

Calling conventions may differ in:

  • Where parameters are placed. Options include registers, on the call stack, a mix of both, or in other memory structures.
  • The order in which parameters are passed. Options include left-to-right order, or right-to-left, or something more complex.
  • How functions that take a variable number of arguments (variadic functions) are handled. Options include just passed in order (presuming the first parameter is in an obvious position) or the variable parts in an array.
  • How return values are delivered from the callee back to the caller. Options include on the stack, in a register, or reference to something allocated on the heap.
  • How long or complex values are handled, perhaps by splitting across multiple registers, within the stack frame, or with reference to memory.
  • Which registers are guaranteed to have the same value when the callee returns as they did when the callee was called. These registers are said to be saved or preserved, so they are not volatile.
  • How the task of setting up for and cleaning up after a function call is divided between the caller and the callee. In particular, how the stack frame is restored so the caller may continue after the callee has finished.
  • Whether and how metadata describing the arguments is passed
  • Where the previous value of the frame pointer is stored, which is used to restore the stack frame when the subroutine ends. Options include within the call stack, or in a specific register. Sometimes frame pointers are not used at all.[2]
  • Where any static scope links for the routine's non-local data access are placed (typically at one or more positions in the stack frame, but sometimes in a general register, or, for some architectures, in special-purpose registers)
  • For object-oriented languages, how the function's object is referenced

Calling conventions within one platform

[edit]

Sometimes multiple calling conventions appear on a single platform; a given platform and language implementation may offer a choice of calling conventions. Reasons for this include performance, adaptation of conventions of other popular languages, and restrictions or conventions imposed by various "computing platforms".

Many architectures only have one widely used calling convention, often suggested by the architect. For RISCs including SPARC, MIPS, and RISC-V, registers names based on this calling convention are often used. For example, MIPS registers $4 through $7 have "ABI names" $a0 through $a3, reflecting their use for parameter passing in the standard calling convention. (RISC CPUs have many equivalent general-purpose registers so there's typically no hardware reason for giving them names other than numbers.)

The calling convention of a given program's language may differ from the calling convention of the underlying platform, OS, or of some library being linked to. For example, on 32-bit Windows, operating system calls have the stdcall calling convention, whereas many C programs that run there use the cdecl calling convention. To accommodate these differences in calling convention, compilers often permit keywords that specify the calling convention for a given function. The function declarations will include additional platform-specific keywords that indicate the calling convention to be used. When handled correctly, the compiler will generate code to call functions in the appropriate manner.

Some languages allow the calling convention for a function to be explicitly specified with that function; other languages will have some calling convention but it will be hidden from the users of that language, and therefore will not typically be a consideration for the programmer.

Architectures

[edit]

x86 (32-bit)

[edit]

The 32-bit version of the x86 architecture is used with many different calling conventions. Due to the small number of architectural registers, and historical focus on simplicity and small code-size, many x86 calling conventions pass arguments on the stack. The return value (or a pointer to it) is returned in a register. Some conventions use registers for the first few parameters which may improve performance, especially for short and simple leaf routines very frequently invoked (i.e. routines that do not call other routines).

Example call:

 push EAX            ; pass some register result
 push dword [EBP+20] ; pass some memory variable (FASM/TASM syntax)
 push 3              ; pass some constant
 call calc           ; the returned result is now in EAX

Typical callee structure: (some or all (except ret) of the instructions below may be optimized away in simple procedures). Some conventions leave the parameter space allocated, using plain ret instead of ret imm16. In that case, the caller could add esp,12 in this example, or otherwise deal with the change to ESP.

calc:
  push EBP            ; save old frame pointer
  mov EBP,ESP         ; get new frame pointer
  sub ESP,localsize   ; reserve stack space for locals
  .
  .                   ; perform calculations, leave result in EAX
  .
  mov ESP,EBP         ; free space for locals
  pop EBP             ; restore old frame pointer
  ret paramsize       ; free parameter space and return.

x86-64

[edit]

The 64-bit version of the x86 architecture, known as x86-64, AMD64, and Intel 64, has two calling sequences in common use. One calling sequence, defined by Microsoft, is used on Windows; the other calling sequence, specified in the AMD64 System V ABI, is used by Unix-like systems and, with some changes, by OpenVMS. As x86-64 has more general-purpose registers than does 32-bit x86, both conventions pass some arguments in registers.

ARM (A32)

[edit]

The standard 32-bit ARM calling convention allocates the 16 general-purpose registers as:

  • r15: Program counter (as per the instruction set specification).
  • r14: Link register. The BL instruction, used in a subroutine call, stores the return address in this register.
  • r13: Stack pointer. The Push/Pop instructions in "Thumb" operating mode use this register only.
  • r12: Intra-Procedure-call scratch register.
  • r4 to r11: Local variables.
  • r0 to r3: Argument values passed to a subroutine and results returned from a subroutine.

If the type of value returned is too large to fit in r0 to r3, or whose size cannot be determined statically at compile time, then the caller must allocate space for that value at run time, and pass a pointer to that space in r0.

Subroutines must preserve the contents of r4 to r11 and the stack pointer (perhaps by saving them to the stack in the function prologue, then using them as scratch space, then restoring them from the stack in the function epilogue). In particular, subroutines that call other subroutines must save the return address in the link register r14 to the stack before calling those other subroutines. However, such subroutines do not need to return that value to r14—they merely need to load that value into r15, the program counter, to return.

The ARM calling convention mandates using a full-descending stack. In addition, the stack pointer must always be 4-byte aligned, and must always be 8-byte aligned at a function call with a public interface.[3]

This calling convention causes a "typical" ARM subroutine to:

  • In the prologue, push r4 to r11 to the stack, and push the return address in r14 to the stack (this can be done with a single STM instruction);
  • Copy any passed arguments (in r0 to r3) to the local scratch registers (r4 to r11);
  • Allocate other local variables to the remaining local scratch registers (r4 to r11);
  • Do calculations and call other subroutines as necessary using BL, assuming r0 to r3, r12 and r14 will not be preserved;
  • Put the result in r0;
  • In the epilogue, pull r4 to r11 from the stack, and pull the return address to the program counter r15. This can be done with a single LDM instruction.

ARM (A64)

[edit]

The 64-bit ARM (AArch64) calling convention allocates the 31 general-purpose registers as:[4]

  • x31 (SP): Stack pointer or a zero register, depending on context.
  • x30 (LR): Procedure link register, used to return from subroutines.
  • x29 (FP): Frame pointer.
  • x19 to x28: Callee-saved.
  • x18 (PR): Platform register. Used for some operating-system-specific special purpose, or an additional caller-saved register.
  • x16 (IP0) and x17 (IP1): Intra-Procedure-call scratch registers.
  • x9 to x15: Local variables, caller saved.
  • x8 (XR): Indirect return value address.
  • x0 to x7: Argument values passed to and results returned from a subroutine.

All registers starting with x have a corresponding 32-bit register prefixed with w. Thus, a 32-bit x0 is called w0.

Similarly, the 32 floating-point registers are allocated as:[5]

  • v0 to v7: Argument values passed to and results returned from a subroutine.
  • v8 to v15: callee-saved, but only the bottom 64 bits need to be preserved.
  • v16 to v31: Local variables, caller saved.

RISC-V ISA

[edit]

RISC-V has a defined calling convention with two flavors, with or without floating point.[6] It passes arguments in registers whenever possible.

POWER, PowerPC, and Power ISA

[edit]

The POWER, PowerPC, and Power ISA architectures have a large number of registers so most functions can pass all arguments in registers for single level calls. Additional arguments are passed on the stack, and space for register-based arguments is also always allocated on the stack as a convenience to the called function in case multi-level calls are used (recursive or otherwise) and the registers must be saved. This is also of use in variadic functions, such as printf(), where the function's arguments need to be accessed as an array. A single calling convention is used for all procedural languages.

Branch-and-link instructions store the return address in a special link register separate from the general-purpose registers; a routine returns to its caller with a branch instruction that uses the link register as the destination address. Leaf routines do not need to save or restore the link register; non-leaf routines must save the return address before making a call to another routine and restore it before it returns, saving it by using the Move From Special Purpose Register instruction to move the link register to a general-purpose register and, if necessary, then saving it to the stack, and restoring it by, if it was saved to the stack, loading the saved link register value to a general-purpose register, and then using the Move To Special Purpose Register instruction to move the register containing the saved link-register value to the link register.

MIPS

[edit]

The O32[7] ABI is the most commonly used ABI, owing to its status as the original System V ABI for MIPS.[8] It is strictly stack-based, with only four registers $a0-$a3 available to pass arguments. This perceived slowness, along with an antique floating-point model with 16 registers only, has encouraged the proliferation of many other calling conventions. The ABI took shape in 1990 and was never updated since 1994. It is only defined for 32-bit MIPS, but GCC has created a 64-bit variation called O64.[9]

For 64-bit, the N64 ABI (not related to Nintendo 64) by Silicon Graphics is most commonly used. The most important improvement is that eight registers are now available for argument passing; It also increases the number of floating-point registers to 32. There is also an ILP32 version called N32, which uses 32-bit pointers for smaller code, analogous to the x32 ABI. Both run under the 64-bit mode of the CPU.[9]

A few attempts have been made to replace O32 with a 32-bit ABI that resembles N32 more. A 1995 conference came up with MIPS EABI, for which the 32-bit version was quite similar.[10] EABI inspired MIPS Technologies to propose a more radical "NUBI" ABI that additionally reuses argument registers for the return value.[11] MIPS EABI is supported by GCC but not LLVM; neither supports NUBI.

For all of O32 and N32/N64, the return address is stored in a $ra register. This is automatically set with the use of the JAL (jump and link) or JALR (jump and link register) instructions. The stack grows downwards.

SPARC

[edit]

The SPARC architecture, unlike most RISC architectures, is built on register windows. There are 24 accessible registers in each register window: 8 are the "in" registers (%i0-%i7), 8 are the "local" registers (%l0-%l7), and 8 are the "out" registers (%o0-%o7). The "in" registers are used to pass arguments to the function being called, and any additional arguments need to be pushed onto the stack. However, space is always allocated by the called function to handle a potential register window overflow, local variables, and (on 32-bit SPARC) returning a struct by value. To call a function, one places the arguments for the function to be called in the "out" registers; when the function is called, the "out" registers become the "in" registers and the called function accesses the arguments in its "in" registers. When the called function completes, it places the return value in the first "in" register, which becomes the first "out" register when the called function returns.

The System V ABI,[12] which most modern Unix-like systems follow, passes the first six arguments in "in" registers %i0 through %i5, reserving %i6 for the frame pointer and %i7 for the return address.

IBM System/360 and successors

[edit]

The IBM System/360 is another architecture without a hardware stack. The examples below illustrate the original calling convention used by OS/360 and successors prior to the introduction of XPLINK and 64-bit z/Architecture; other operating systems for System/360 AND later might have different calling conventions.

Calling program:

     LA  1,ARGS      Load argument list address
     L   15,=V(SUB)  Load subroutine address1
     BALR 14,15      Branch to called routine2
     ...
ARGS DC A(FIRST)     Address of 1st argument
     DC A(SECOND)
     ...
     DC A(THIRD)+X'80000000' Last argument3

Called program:

SUB  EQU *            This is the entry point of the subprogram4

Standard entry sequence:

     USING *,155
     STM 14,12,12(13) Save registers6
     ST  13,SAVE+4    Save caller's savearea addr
     LA  12,SAVE      Chain saveareas
     ST  12,8(13)
     LR  13,12
     ...

Standard return sequence:

     L   13,SAVE+47
     LM  14,12,12(13)
     L   15,RETVAL8
     BR  14          Return to caller
SAVE DS  18F         Savearea9

Notes:

  1. Use L 15,=A(SUB) or LA 15,SUB for internal subroutine; use L 15,=V(SUB) for external subroutines.
  2. The BALR instruction stores the address of the next instruction (return address) in the register specified by the first argument—register 14—and branches to the second argument address in register 15. BASR is preferred on models that support it. BASSM may be used if switching between 24 and 31 bit modes is required.
  3. The caller passes the address of a list of argument addresses in register 1. The last address has the high-order bit set to indicate the end of the list. This limits programs using this convention to 31-bit addressing.
  4. For external subroutines, either include SUB ENTRY , after SUB EQU * or replace it with SUB CSECT ,.
  5. The address of the called routine is in register 15. Normally this is loaded into another register with DROP and USING informing the assembler that register 15 is no longer to be used as a base register.
  6. The STM instruction saves registers 14, 15, and 0 through 12 in a 72-byte area provided by the caller called a save area pointed to by register 13. The called routine provides its own save area for use by subroutines it calls; the address of this area is normally kept in register 13 throughout the routine. The instructions following STM update forward and backward chains linking this save area to the caller's save area.
  7. The return sequence restores the caller's registers.
  8. Register 15 is usually used to pass a return value. The code shown is incorrect but illustrates the principle.
  9. Declaring a savearea statically in the called routine makes it non-reentrant and non-recursive; a reentrant program uses a dynamic savearea, acquired either from the operating system and freed upon returning, or in storage passed by the calling program.

In the System/390 ABI[13] and the z/Architecture ABI,[14] used in Linux:

  • Registers 0 and 1 are volatile
  • Registers 2 and 3 are used for parameter passing and return values
  • Registers 4 and 5 are also used for parameter passing
  • Register 6 is used for parameter passing, and must be saved and restored by the callee
  • Registers 7 through 13 are for use by the callee, and must be saved and restored by them
  • Register 14 is used for the return address
  • Register 15 is used as the stack pointer
  • Floating-point registers 0 and 2 are used for parameter passing and return values
  • Floating-point registers 4 and 6 are for use by the callee, and must be saved and restored by them
  • In z/Architecture, floating-point registers 1, 3, 5, and 7 through 15 are for use by the callee
  • Access register 0 is reserved for system use
  • Access registers 1 through 15 are for use by the callee

Additional arguments are passed on the stack.

SuperH

[edit]
Register Windows CE 5.0 gcc Renesas
R0 Return values. Temporary for expanding assembly pseudo-instructions. Implicit source/destination for 8/16-bit operations. Not preserved. Return value, caller saves Variables/temporary. Not guaranteed
R1..R3 Serves as temporary registers. Not preserved. Caller saved scratch. Structure address (caller save, by default) Variables/temporary. Not guaranteed
R4..R7 First four words of integer arguments. The argument build area provides space into which R4 through R7 holding arguments may spill. Not preserved. Parameter passing, caller saves Arguments. Not guaranteed.
R8..R13 Serves as permanent registers. Preserved. Callee Saves Variables/temporary. Guaranteed.
R14 Default frame pointer. (R8-R13 may also serve as frame pointer and leaf routines may use R1–R3 as frame pointer.) Preserved. Frame Pointer, FP, callee saves Variables/temporary. Guaranteed.
R15 Serves as stack pointer or as a permanent register. Preserved. Stack Pointer, SP, callee saves Stack pointer. Guaranteed.

Note: "preserved" reserves to callee saving; same goes for "guaranteed".

68k

[edit]

The most common calling convention for the Motorola 68000 series is:[15][16][17][18]

  • d0, d1, a0 and a1 are scratch registers
  • All other registers are callee-saved
  • a6 is the frame pointer, which can be disabled by a compiler option
  • Parameters are pushed onto the stack, from right to left
  • Return value is stored in d0

IBM 1130

[edit]

The IBM 1130 was a small 16-bit word-addressable machine. It had only six registers plus condition indicators, and no stack. The registers are Instruction Address Register (IAR), Accumulator (ACC), Accumulator Extension (EXT), and three index registers X1–X3. The calling program is responsible for saving ACC, EXT, X1, and X2.[19] There are two pseudo-operations for calling subroutines, CALL to code non-relocatable subroutines directly linked with the main program, and LIBF to call relocatable library subroutines through a transfer vector.[20] Both pseudo-ops resolve to a Branch and Store IAR (BSI) machine instruction that stores the address of the next instruction at its effective address (EA) and branches to EA+1.

Arguments follow the BSI?—?usually these are one-word addresses of arguments?—?the called routine must know how many arguments to expect so that it can skip over them on return. Alternatively, arguments can be passed in registers. Function routines returned the result in ACC for real arguments, or in a memory location referred to as the Real Number Pseudo-Accumulator (FAC). Arguments and the return address were addressed using an offset to the IAR value stored in the first location of the subroutine.

  *                  1130 subroutine example
     ENT  SUB        Declare "SUB" an external entry point
 SUB DC   0          Reserved word at entry point, conventionally coded "DC *-*"
 *                   Subroutine code begins here
 *                   If there were arguments the addresses can be loaded indirectly from the return address
     LDX I 1 SUB     Load X1 with the address of the first argument (for example)
 ...
 *                   Return sequence
     LD      RES     Load integer result into ACC
 *                   If no arguments were provided, indirect branch to the stored return address
     B   I   SUB     If no arguments were provided
     END  SUB

Subroutines in IBM 1130, CDC 6600 and PDP-8 (all three computers were introduced in 1965) store the return address in the first location of a subroutine.[21]

Calling conventions outside machine architectures

[edit]

Threaded code

[edit]

Threaded code places all the responsibility for setting up for and cleaning up after a function call on the called code. The calling code does nothing but list the subroutines to be called. This puts all the function setup and clean-up code in one place—the prologue and epilogue of the function—rather than in the many places that function is called. This makes threaded code the most compact calling convention.

Threaded code passes all arguments on the stack. All return values are returned on the stack. This makes naive implementations slower than calling conventions that keep more values in registers. However, threaded code implementations that cache several of the top stack values in registers—in particular, the return address—are usually faster than subroutine calling conventions that always push and pop the return address to the stack.[22][23][24]

PL/I

[edit]

The default calling convention for programs written in the PL/I language passes all arguments by reference, although other conventions may optionally be specified. The arguments are handled differently for different compilers and platforms, but typically the argument addresses are passed via an argument list in memory. A final, hidden, address may be passed pointing to an area to contain the return value. Because of the wide variety of data types supported by PL/I a data descriptor may also be passed to define, for example, the lengths of character or bit strings, the dimension and bounds of arrays (dope vectors), or the layout and contents of a data structure. Dummy arguments are created for arguments which are constants or which do not agree with the type of argument the called procedure expects.

See also

[edit]

References

[edit]
  1. ^ a b "Calling Conventions". cs.cornell.edu. Retrieved 2025-08-14.
  2. ^ "/Oy (Frame-Pointer Omission)". learn.microsoft.com. 3 August 2021. Retrieved 2025-08-14.
  3. ^ "Procedure Call Standard for the ARM Architecture". 2021.
  4. ^ "Parameters in general-purpose registers". ARM Cortex-A Series Programmer’s Guide for ARMv8-A. Retrieved 12 November 2020.
  5. ^ "Parameters in NEON and floating-point registers". developer.arm.com. Retrieved 13 November 2020.
  6. ^ "RISC-V calling convention" (PDF).
  7. ^ "MIPS32 Instruction Set Quick Reference".
  8. ^ Sweetman, Dominic. See MIPS Run (2 ed.). Morgan Kaufmann Publishers. ISBN 0-12088-421-6.
  9. ^ a b "MIPS ABI History".
  10. ^ Christopher, Eric (11 June 2003). "mips eabi documentation". binutils@sources.redhat.com (Mailing list). Retrieved 19 June 2020.
  11. ^ "NUBI".
  12. ^ System V Application Binary Interface SPARC Processor Supplement (3 ed.).
  13. ^ "S/390 ELF Application Binary Interface Supplement".
  14. ^ "zSeries ELF Application Binary Interface Supplement".
  15. ^ Smith, Dr. Mike. "SHARC (21k) and 68k Register Comparison".
  16. ^ XGCC: The Gnu C/C++ Language System for Embedded Development (PDF). Embedded Support Tools Corporation. 2000. p. 59.
  17. ^ "COLDFIRE/68K: ThreadX for the Freescale ColdFire Family". Archived from the original on 2025-08-14.
  18. ^ Moshovos, Andreas. "Subroutines Continued: Passing Arguments, Returning Values and Allocating Local Variables". all registers except d0, d1, a0, a1 and a7 should be preserved across a call.
  19. ^ IBM Corporation (1967). IBM 1130 Disk Monitor System, Version 2 System Introduction (C26-3709-0) (PDF). p. 67. Retrieved 21 December 2014.
  20. ^ IBM Corporation (1968). IBM 1130 Assembler Language (C26-5927-4) (PDF). pp. 24–25.
  21. ^ Smotherman, Mark (2004). "Subroutine and procedure call support: Early history".
  22. ^ Rodriguez, Brad. "Moving Forth, Part 1: Design Decisions in the Forth Kernel". On the 6809 or Zilog Super8, DTC is faster than STC.
  23. ^ Ertl, Anton. "Speed of various interpreter dispatch techniques".
  24. ^ Zaleski, Mathew (2008). "Chapter 4: Design and Implementation of Efficient Interpretation". YETI: a graduallY Extensible Trace Interpreter. Although direct-threaded interpreters are known to have poor branch prediction properties... the latency of a call and return may be greater than an indirect jump.
[edit]
宫颈醋酸白色上皮是什么病变 堃什么意思 梦见请别人吃饭是什么意思 药剂科是干什么的 为什么健身
久旱逢甘露是什么意思 怀孕为什么会流褐色分泌物 吃胎盘有什么好处 魏大勋和李沁什么关系 什么草
黄疸是什么症状 出汗多是什么病 胆囊壁结晶是什么意思 讣告是什么意思 vos是什么意思
芒硝有什么作用 bn是什么颜色 总蛋白低是什么意思 防弹衣为什么能防弹 排斥是什么意思
眉尾有痣代表什么liaochangning.com 6月20号什么星座hcv8jop4ns2r.cn 龙傲天是什么意思hcv7jop5ns6r.cn 什么是行政拘留hcv9jop1ns9r.cn 神经纤维瘤是什么病onlinewuye.com
沂字五行属什么liaochangning.com 什么肥什么壮hcv9jop7ns3r.cn 肾亏是什么意思hcv7jop6ns9r.cn qid是什么意思hcv8jop3ns0r.cn 卧室养什么花好zhongyiyatai.com
胃烧灼感是什么原因引起的hcv9jop1ns7r.cn 心血管疾病做什么检查xjhesheng.com 山东特产是什么生肖hcv9jop5ns6r.cn 产后恶露吃什么排干净hcv8jop6ns3r.cn 肛门疼是什么原因travellingsim.com
做梦买鞋是什么意思xjhesheng.com 口臭去医院挂什么科室看病hcv7jop7ns3r.cn 扁桃体结石有什么危害hcv9jop5ns1r.cn 悲戚是什么意思naasee.com 表里不一是什么意思hcv9jop1ns3r.cn
百度