Jump added
This commit is contained in:
118
x86_64/3_jump.asm
Normal file
118
x86_64/3_jump.asm
Normal file
@@ -0,0 +1,118 @@
|
||||
global _start
|
||||
|
||||
; Static data
|
||||
section .data
|
||||
promptStr: db 'Write something! (max 32 bytes)',0xA
|
||||
promptStrSize: equ $ - promptStr
|
||||
|
||||
unusedStr: db "This string won't be printed",0xA
|
||||
unusedStrSize: equ $ - unusedStr
|
||||
|
||||
lessStr: db 'The input string has less than 16 bytes',0xA
|
||||
lessStrSize: equ $ - lessStr
|
||||
|
||||
moreStr: db 'The input string has 16 bytes or more',0xA
|
||||
moreStrSize: equ $ - moreStr
|
||||
|
||||
; Dynamic data
|
||||
section .bss
|
||||
inputBuffer: resb 32
|
||||
inputBufferSize: equ 32
|
||||
|
||||
; Code
|
||||
section .text
|
||||
_start:
|
||||
mov rax, 1
|
||||
mov rdi, 1 ; stdout
|
||||
mov rsi, promptStr
|
||||
mov rdx, promptStrSize
|
||||
syscall
|
||||
|
||||
jmp request_input
|
||||
|
||||
; Skipped over
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, unusedStr
|
||||
mov rdx, unusedStrSize
|
||||
syscall
|
||||
|
||||
request_input:
|
||||
xor rax, rax ; 0 = read
|
||||
xor rdi, rdi ; 0 = stdin
|
||||
mov rsi, inputBuffer
|
||||
mov rdx, inputBufferSize
|
||||
syscall
|
||||
|
||||
mov rbx, rax ; store read bytes
|
||||
|
||||
; *** FLAGS *** (16 bit era)
|
||||
; Bit Abbreviation Description
|
||||
; 0 CF Carry Flag (1 = carry, 0 = no carry)
|
||||
; 2 PF Parity Flag (1 = even, 0 = uneven)
|
||||
; 4 AF Adjust Flag (1 = auxiliary carry, 0 no ...)
|
||||
; 6 ZF Zero Flag (1 = zero, 0 = non zero)
|
||||
; 7 SF Sign Flag (1 = negative, 0 = positive)
|
||||
; 8 TF Trap Flag
|
||||
; 9 IF Interrupt Flag (1 = enabled, 0 = disabled)
|
||||
; 10 DF Direction Flag (1 = down, 0 = up)
|
||||
; 11 OF Overflow Flag (1 = overflow, 0 = no overflow)
|
||||
; 12 --v
|
||||
; 13 IOPL IO Privilege Level
|
||||
; 14 NT Nested Task
|
||||
;
|
||||
; *** EFLAGS *** (32 bit era)
|
||||
; 16 RF Resume Flag
|
||||
; 17 VM Virtual 8086 mode
|
||||
; 18 AC Alignment check
|
||||
; 19 VIF Virtual Interrupt Flag
|
||||
; 20 VIP Virtual Interrupt Pending
|
||||
; 21 ID CPUID enabled flag
|
||||
;
|
||||
; *** RFLAGS *** (64 bit era)
|
||||
; - - None yet
|
||||
|
||||
; Subtraction without storing the result
|
||||
cmp rbx, 16
|
||||
; Jump based upon the flags set above
|
||||
jl less_than_16
|
||||
|
||||
; >= 16 bytes
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, moreStr
|
||||
mov rdx, moreStrSize
|
||||
syscall
|
||||
|
||||
jmp size_printed
|
||||
|
||||
less_than_16:
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, lessStr
|
||||
mov rdx, lessStrSize
|
||||
syscall
|
||||
|
||||
size_printed:
|
||||
dec rbx ; subtract the newline from the count
|
||||
|
||||
xor rcx, rcx ; loop variable
|
||||
loop_begin:
|
||||
cmp rcx, rbx ; while loop var < (string size - 1)
|
||||
jge loop_end
|
||||
inc byte [inputBuffer + rcx]
|
||||
inc rcx
|
||||
jmp loop_begin
|
||||
|
||||
loop_end:
|
||||
inc rbx ; restore original bytes read count
|
||||
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, inputBuffer
|
||||
mov rdx, rbx
|
||||
syscall
|
||||
|
||||
mov rax, 60
|
||||
xor rdi, rdi
|
||||
syscall ; see ya
|
||||
Reference in New Issue
Block a user