首页 > 编程语言 >汇编语言中的ORG指令

汇编语言中的ORG指令

时间:2024-03-22 23:58:36浏览次数:27  
标签:汇编语言 DC 指令 org ORG boundary translate TABLE

一 ORG指令

ORG是Origin的缩写:起始地址,源。在汇编语言源程序的开始通常都用一条ORG伪指令来实现规定程序的起始地址。如果不用ORG规定则汇编得到的目标程序将从0000H开始。例如:

            ORG 2000H   
   START:MOV  AX,#00H

汇编语言源程序中若没有ORG伪指令,则程序执行时,指令代码被放到自由内存空间的CS:0处;若有ORG伪指令,编译器则把其后的指令代码放到ORG伪指令指定的偏移地址。两个ORG伪指令之间,除了指令代码,若有自由空间,则用0填充。

预处理–>编译–>汇编–>链接,这是高级语言的编译全过程。对于纯汇编,就只有汇编和链接两个步骤。

org指令是链接时使用的,不是汇编那一步使用的。即不是cpu的一条指令,而是给编译器看的伪指令。

在51单片机、x86 dos、win32 exe中实现都有差异。

以最简单的51单片机为例,编译器最终链接生成HEX文件,再烧录到51的rom中去。单片机很简单,没有x86的分段、分页,启动就是从rom的0x0的位置开始执行。同时0x30H位置开始存放中断向量,
所以单片机程序一般开头就是:

   ORG 0000H


   AJMP MAIN


   ORG 0030H

这里的ORG 0000H指令,使得程序链接成HEX文件时,AJMP MAIN这条指令的机器码就在HEX文件的0x0位置。这是链接器的工作。

二 英文版

ORG用来自定义程序的起始位置,从而达到control section和 REDFEIN portions的目的

If a control section has not been previously established, ORG initiates an unnamed (private) control section.

>>-+--------+--ORG---------------------------------------------->
   '-symbol-'        

>--+--------------------------------------------+--------------><
   '-expression-+-----------------------------+-'   
                '-,-+-boundary--+---------+-+-'     
                    |           '-,offset-' |       
                    '-,--offset-------------'       

这玩意内部可以分成如上图所示
symbol
Is one of the following:

  • An ordinary symbol
  • A variable symbol that has been assigned a character string with a value
    that is valid for an ordinary symbol
  • A sequence symbol。

If symbol denotes an ordinary symbol, the ordinary symbol is defined with the value that the location counter had before the ORG statement is processed.

expression
Is a relocatable expression, the value of which is used to set the location counter. If expression is omitted, the location counter is set to the next available location for the current control section.
boundary
Is an absolute expression that must be a number that is a power of 2 with a range from 2 (halfword) to 4096 (page). If boundary exceeds the SECTALGN value, message ASMA500E is issued. This message is not issued if the section being processed is a Reference Control Section (DSECT, DXD, or COM).
boundary must be a predefined absolute expression whose value is known at the time the ORG statement is processed.

If the boundary operand is greater than 16, the GOFF option must be specified in addition to the SECTALGN option.

offset
Any absolute expression
If boundary or offset are provided, then the resultant location counter is calculated by rounding the expression up to the next higher boundary and then adding the offset value.

origin   csect
         ds    235x               Define 235 bytes
         org   origin,,3          Move location counter back to start + 3
         org   *,8                Align on 8 byte boundary
         org   *,8,-2             Align to 8 byte boundary -2 bytes
translate dc   cl256' '           Define aligned translate table
         org   translate+c'a'
         dc    c'ABCDEFGHI'
         org   translate+c'j'
         dc    c'JKLMNOPQR'
         org   translate+c's'
         dc    c'STUVWXYZ'
         org   translate+c'A'
         dc    c'ABCDEFGHI'
         org   translate+c'J'
         dc    c'JKLMNOPQR'
         org   translate+c'S'
         dc    c'STUVWXYZ'
         org   ,
         end

下面是上面那个程序的解析

                  Source Module                      │      Object Code
─────────────────────────────────────────────────────┼────────────────────────
                                                     │
          FIRST    START 0                           │
                   .                                 │
                   .                                 │
 1        TABLE    DC    XL256'0'                    │ TABLE   (in Hex)
 2                 ORG   TABLE+0                     │ +0       ┌────┐
        ┌          DC    C'0'        3               │          │ F0 │
        │          DC    C'1'                        │          │ F1 │
        │          .                                 │          │ .  │
        │          .                                 │          │ .  │
        │          ORG   TABLE+13                    │ +13      │ .  │
        │          DC    C'D'                        │          │ C4 │
        │          DC    C'E'                        │          │ C5 │
        │          .                                 │          │ .  │
        │          .                                 │          │ .  │
 4     ─┤          ORG   TABLE+C'D'                  │          │ .  │
        │          DC    AL1(13)                     │ +196     │ 13 │
        │          DC    AL1(14)                     │          │ 14 │
        │          .                                 │          │ .  │
        │          .                                 │          │ .  │
        │          ORG   TABLE+C'0'                  │ +240     │ .  │
        │          DC    AL1(0)                      │          │ 00 │
        │          DC    AL1(1)                      │          │ 01 │
        │          .                                 │          │    │
        └          .                                 │ +255     └────┘
                   ORG                               │
 5        GOON     DS    0H                          │
∧                  .                                 │
TABLE+256          .                                 │
                   TR    INPUT,TABLE                 │
                   .                                 │
                   .                                 │
          INPUT    DS    CL20                        │
                   .                                 │
                   .                                 │
                   END                               │

标签:汇编语言,DC,指令,org,ORG,boundary,translate,TABLE
From: https://blog.csdn.net/CNMBZY/article/details/136954720

相关文章

  • ThinkPHP自定义指令
    官网文档https://www.kancloud.cn/manual/thinkphp6_0/1037651创建命令类文件运行指令创建一个自定义命令类文件phpthinkmake:commandHellohello生成内容如下<?phpnamespaceapp\command;usethink\console\Command;usethink\console\Input;usethink\console\in......
  • C.S远程指令控制
    C.S远程指令控制一.模型结构​​客户端:客户端首先创建一个套接字,该套接字绑定的是目标IP和端口,在调用connect函数的时候将自己的IP和端口发送给服务器。服务端:服务端首先创建一个套接字,该套接字和自身IP以及端口绑定,在调用accept函数的时候,从缓冲区将客户端的IP和端口提取......
  • Docker指令
    systemctlstartdocker启动dockersystemctlstopdocker关闭dockersystemctlstatusdocker查看运行状态systemctlrestartdocker重启dockersystemctlpull镜像名拉去镜像dockerrun镜像名运行镜像dockerrmi-f镜像名/镜像Iddockerrmi-f$(dockerimage-......
  • uniapp 蓝牙连接斑马打印机发送zpl指令打印
    历程需求是想通过斑马的zpl语言打印小票等,需要用到蓝牙连接。一开始采用的是uniapp自带的蓝牙连接和打印,用的是uni.writeBLECharacteristicValue(OBJECT)方法,蓝牙能正常连接和发送数据。奇怪的是发送蓝牙数据始终都是ok,打印机确是一点动静都没有。基于以上的疑惑,我开始怀疑是u......
  • 【视觉语言大模型+LLaVA1.0】大语言模型视觉助手(视觉指令调优)GPT4-Vision丐版
    官方资源汇总:项目主页||https://huggingface.co/liuhaotian23.04.LLaVA1.论文:LargeLanguageandVisionAssistant(VisualInstructionTuning)23.10LLaVA-1.5论文:ImprovedBaselineswithVisualInstructionTuning23.11LLaVA-Plus项目:LLaVA-Plus:LargeLang......
  • 城轨列车智能指令控制模块技术研讨
    城轨列车智能指令控制模块技术研讨研发中心二〇二一年  1. 概述智能指令控制模块是一种应用于全自动无人驾驶轨道交通车辆上操作面板模块,该模块旨在提供一种统一的智能化、标准化、人性化、便捷化的高可靠性且易于维护的解决方案。该模块用于实现车辆运行状态的指示和操作......
  • 一学就会 | ChatGPT提示词-[简历指令库]-有爱AI实战教程(八)
    演示站点:  https://ai.uaai.cn 对话模块官方论坛:  www.jingyuai.com 京娱AI 一、导读:在使用ChatGPT时,当你给的指令越精确,它的回答会越到位,举例来说,假如你要请它帮忙写文案,如果没给予指定情境与对象,它会不知道该如何回答的更加准确。当你看到199的教程时,......
  • 汇编语言中的MVC
    一MVC指令1.移动字符串指令MVC移动字符串指令MVC的格式为:MVCD1(L,B1),D2(B2)(移动字符串)功能:(D1+(B1))←(D2+(B2))L个字符指令的执行用开始于D2(B2)的L字节替换开始于D1(B1)的L字节的内容。L个字节的内容每次改变一个,从左边开始。如果域不重叠的话,这一事实是不重要的,但......
  • C++ <atomic>汇编语言实现原理
    C++<atomic>汇编语言实现原理问题我们先看一下这段代码:/**badcnt.c-Animproperlysynchronizedcounterprogram*//*$beginbadcnt*//*WARNING:Thiscodeisbuggy!*/#include"csapp.h"void*thread(void*vargp);/*Threadroutineprototype*//*......
  • #pragma指令
    pragma是一个在C和C++中使用的编译器指令,用于向编译器发出特定的命令或控制编译的行为。控制编译警告通过#pragmawarning指令,可以在特定位置或范围内控制编译器的警告行为,如禁止某个警告、将警告作为错误处理等。例如禁止特定的编译警告:#pragmawarning(disable:4996)......