Ubuntu 20.04下配置 HAL 汇编开发环境教程

安装

环境:Ubuntu 20.04

安装包:linux64.hla.tar.gz

这里安装的是64位的,具体与linux.hla.tar.gz有什么不同,没研究过。

解压

可任选目录,本文在我的用户目录/home/nqw下解压。

$ tar -xvf linux64.hla.tar.gz

解压后会自动创建子目录/usr/hla,文件都保存在这个目录下。其中code文件夹是笔者自己添加的,用来保存以后编写的代码。

在这里插入图片描述

配置环境变量
$ gedit ~/.bashrc

在打开的文件末尾,添加如下内容,主要是配置hla的可执行文件路径、库路径、头文件路径等。

PATH=/home/nqw/usr/hla:$PATH
export PATH
hlalib=/home/nqw/usr/hla/hlalib
export hlalib
hlainc=/home/nqw/usr/hla/include
export hlainc
hlacode=/home/nqw/usr/hla/code
export hlacode

保存,退出。

执行如下指令生效。

$ source ~/.bashrc  
测试

检测hla版本,看是否安装成功。

$ hla -v

得到如下信息,表示安装成功。

$ hla -v
HLA (High Level Assembler)
Use '-license' to see licensing information.
Version 2.16 build 4409 (prototype)
ELF output
OBJ output using HLA Back Engine
-test active

HLA Lib Path:     /hla/usr/hla/hlalib/hlalib.a
HLA include path: /hla/usr/hla/include
HLA temp path:    
Files:

Nothing more to do!
Usage: hla options filename(s)

HLA (High Level Assembler - HLABE back end, LD linker)
Version 2.16 build 4409 (prototype)

  -?        Display help message.
  -license  Display license information.

案例

code文件夹下,创建文件hw.hla,并编辑如下内容。

program helloworld;
#include("stdlib.hhf")

begin helloworld;

stdout.put("Hello,world!!!", nl);

end helloworld;

编译

$ hla -v hw.hla

这个时候可能会报如下错误,提示找不到hlaparse

sh: 1: hlaparse: not found

网上关于这个的帖子较少,不过找到一个,大致意思好像是需要32位的链接器。

安装libc6-i386

$ sudo apt install libc6-i386

然后重新编译,基本就解决了。

nqw@ubuntu:~/usr/hla/code$ hla -v hw.hla 
HLA (High Level Assembler)
Use '-license' to see licensing information.
Version 2.16 build 4463 (prototype)
ELF output
OBJ output using HLA Back Engine
-test active

HLA Lib Path:     /home/nqw/usr/hla/hlalib/hlalib.a
HLA include path: /home/nqw/usr/hla/include
HLA temp path:    
Files:
1: hw.hla

Compiling 'hw.hla' to 'hw.o'
using command line:
[hlaparse -LINUX -level=high  -v -test "hw.hla"]

----------------------
HLA (High Level Assembler) Parser
use '-license' to view license information
Version 2.16 build 4463 (prototype)
-test active
File: hw.hla
Output Path: ""
hlainc Path: "/home/nqw/usr/hla/include"
hlaauxinc Path: ""
Compiler generating code for Linux OS
Back-end assembler: HLABE
Language Level: high

Assembling "hw.hla" to "hw.o"
HLAPARSE assembly complete, 48342 lines,   0.074 seconds,  652389 lines/second
------------
HLA Back Engine Object code formatter

HLABE compiling 'hw.hla' to 'hw.o'
Optimization passes: 3+2
----------------------
Linking via [ld  -melf_i386    -o "hw"    "hw.o" "/home/nqw/usr/hla/hlalib/hlalib.a"]

========================================
    HLA Compilation Complete
========================================

运行。

nqw@ubuntu:~/usr/hla/code$ ls
hw  hw.hla  hw.o
nqw@ubuntu:~/usr/hla/code$ ./hw 
Hello,world!!!

到这里,linux下hla的基本编程环境就配置好啦。