string555
Banned
- 1,373
- Posts
- 7
- Years
- Wonderland
- Seen Mar 14, 2018
Anyone ever had to deal with so called "AnsiString"? They're an relict of ancient Delphi versions only kept around for compatibility. Before the advent of UTF-8 in the Delphi world, they were pretty much the standard in any Delphi version, up to a point where normal Strings were actually just AnsiStrings, but with a different name. Later on Strings became UTF-8-Strings.
Now imagine you work at a company that is migrating code from an old Delphi version to a newer one and your company made the decision to continue using AnsiString.
Considering my username, you would think I could help you with that problem, but sorry. :P
I'm still suppose to be focusing on studying C programming, but the other day I dumped the contents of one of my executables to examine what assembly code looked like. After staring at it and not really knowing wtf it was doing, I decided to go off on a wild tangent for a bit and learn some assembly. So here's a sample written in Ubuntu 64-bit Intel Assembly:
Spoiler:
Code:
[SIZE="2"]
;===================================================
; tt.asm Generate a 4x4 times table
; Assemble: nasm -f elf64 -l tt.lst tt.asm
; Link: gcc -m64 -o tt tt.o
; Run: ./tt
; One line: nasm -f elf64 -l tt.lst tt.asm && gcc -m64 -o tt tt.o && ./tt
;==============================================
;==============================================
; Declare needed C functions
extern printf ; the C function, to be called
;==============================================
section .data ; Data section, initialized variables
t: dq 1 ; The following 'n' variables have changing values
n1: dq 1
n2: dq 2
n3: dq 3
n4: dq 4
c1: dq 1 ; The following 'c' variables are constants
c2: dq 2
c3: dq 3
c4: dq 4
fmt1: db "", 10, 0 ; The printf format, "\n",'0'
fmt2: db " %ld %ld %ld %ld", 10, 0 ; printf format for initial line
fmt3: db "%ld %ld %ld %ld %ld", 10, 0 ; printf format for the rest
;==============================================
section .text ; Code section.
global main ; the standard gcc entry point
main: ; the program label for the entry point
push rbp ; set up stack frame, must be aligned
mov rdi,fmt1 ; move 1st format string into rdi
mov rax,0 ; clear out rax
call printf ; call printf
mov rdi,fmt2 ; move 2nd format string into rdi (1st arg)
mov rsi,[n1] ; move n1 var into rsi (2nd arg)
mov rdx,[n2] ; move n2 var into rsi (3rd arg)
mov rcx,[n3] ; move n3 var into rcx (4th arg)
mov r8,[n4] ; move n4 var into r8 (5th arg)
mov rax,0 ; clear out rax (If left out, might cause problems)
call printf ; call printf
loop1:
mov rax,[t] ; Move t into rax
imul qword [c1] ; Multiply rax value by c1
mov [n1],rax ; Move rax value into n1
mov rax,[t] ; Move t into rax
imul qword [c2] ; Multiply rax value by c2
mov [n2],rax ; Move rax value into n2
mov rax,[t] ; Move t into rax
imul qword [c3] ; Multiply rax value by c3
mov [n3],rax ; Move rax value into n3
mov rax,[t] ; Move t into rax
imul qword [c4] ; Multiply rax value by c4
mov [n4],rax ; Move rax value into n3
mov rdi,fmt3 ; Move 3rd format string into rdi (1st arg)
mov rsi,[t] ; Move t into rsi (2nd arg)
mov rdx,[n1] ; Move n1 into rdx (3rd arg)
mov rcx,[n2] ; Move n2 into rcx (4th arg)
mov r8,[n3] ; Move n3 into r8 (5th arg)
mov r9,[n4] ; Move n4 into r9 (6th arg)
mov rax,0 ; Clear out rax
call printf ; Call printf (You know this by now :P)
mov rax,[t] ; Move t into rax for addition
add rax,1 ; Add 1 to rax value
mov [t],rax ; Mov new rax value back into t (Essentially t++)
cmp rax,5 ; Compare value in rax to the limit 5
jl loop1 ; If rax value was less than limit, goto 'loop1:'
;End loop1
pop rbp ; restore stack
mov rax,0 ; normal, no error, return value
ret ; return
;==================================================================
[/SIZE]
Since I haven't learned how to accept user input in Assembly yet, this is the most I've been able to do with it so far. XD