Skip to content

Commit

Permalink
learn: string memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
hirohito-protagonist committed Dec 30, 2017
1 parent bd5bd58 commit 81d6565
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 0 deletions.
169 changes: 169 additions & 0 deletions src/string-allocation.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
; Assembly code emitted by HLA compiler
; Version 2.16 build 4413 (prototype)
; HLA compiler written by Randall Hyde
; NASM compatible output

bits 32

%define ExceptionPtr__hla_ [dword fs:0]


global QuitMain__hla_
global DfltExHndlr__hla_
global _HLAMain
global HWexcept__hla_
global start


section .text code align=16


extern STDIN_FLUSHINPUT
extern STR_ALLOC1
extern STDOUT_NEWLN
extern DefaultExceptionHandler__hla_
extern abstract__hla_
extern HardwareException__hla_
extern STDIN_GETS
extern BuildExcepts__hla_
extern STDOUT_PUTS
extern Raise__hla_
extern shortDfltExcept__hla_






section .text




;/* HWexcept__hla_ gets called when Windows raises the exception. */


; procedure HWexcept__hla_

HWexcept__hla_:
jmp HardwareException__hla_
;HWexcept__hla_ endp


; procedure DfltExHndlr__hla_

DfltExHndlr__hla_:
jmp DefaultExceptionHandler__hla_
;DfltExHndlr__hla_ endp




; procedure _HLAMain

_HLAMain:
nop


; procedure start

start:
;start endp

call BuildExcepts__hla_
; push dword 0
db 06ah ;
db 00h ;
; push ebp
db 055h ;
; push ebp
db 055h ;
; lea ebp, [esp+4]
db 08dh ;
db 06ch ;
db 024h ;
db 04h ;


; push dword 16
db 06ah ;
db 010h ;
call STR_ALLOC1
; mov [strExample__hla_1885], eax
db 0a3h ;
dd (strExample__hla_1885+0)
; push strict dword str__hla_1889
db 068h ;
dd str__hla_1889
call STDOUT_PUTS
call STDIN_FLUSHINPUT
; push dword [strExample__hla_1885]
db 0ffh ;
db 035h ;
dd strExample__hla_1885
call STDIN_GETS
; push strict dword str__hla_1890
db 068h ;
dd str__hla_1890
call STDOUT_PUTS
; push dword [strExample__hla_1885]
db 0ffh ;
db 035h ;
dd strExample__hla_1885
call STDOUT_PUTS
call STDOUT_NEWLN
QuitMain__hla_:
; push dword 0
db 06ah ;
db 00h ;
; call [__imp__ExitProcess@4]
db 0ffh ;
db 015h ;
dd __imp__ExitProcess@4
;_HLAMain endp









section .text


align (4)
len__hla_1889 dd 024h
dd 024h
str__hla_1889:
db "Type some text (max 16 characters): "
db 0

db 0
db 0
db 0

align (4)
len__hla_1890 dd 03h
dd 03h
str__hla_1890:
db "-> "
db 0





section .data data align=16

extern MainPgmCoroutine__hla_
extern __imp__MessageBoxA@16
extern __imp__ExitProcess@4
align (4)
strExample__hla_1885 times 4 db 0





16 changes: 16 additions & 0 deletions src/string-allocation.hla
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
program StringAllocationDemo;
#include("stdlib.hhf")

static
strExample: string;
begin StringAllocationDemo;

str.alloc(16);
mov(eax, strExample);

stdout.put("Type some text (max 16 characters): ");
stdin.flushInput();
stdin.gets(strExample);

stdout.put("-> ", strExample, nl);
end StringAllocationDemo;

0 comments on commit 81d6565

Please sign in to comment.