Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ASCII to HEX and display again
;nasm 2.13.02 section .data m1 db 'Enter 2 digit number',10d,13d ; 10D is line feed(new line)and 13D(set cursor) is carriage return l1 equ $-m1 m2 db 'The 2 digit number is=',10d,13d l2 equ $-m2 m3 db " ",10d,13d ; Declared for spaces l3 equ $-m3 %macro read_write 4 mov rax,%1 ; Function for sys_write mov rdi,%2 ; File descriptor id for i/o mov rsi,%3 ; Memory address of m1 mov rdx,%4 ; count of bytes to be displayed syscall ; call kernel %endmacro section .bss ; block starting symbol for uninitialized var num RESB 20 ; Reserve 20 bytes for num variable array RESB 200 char_ans RESB 16 section .text global _start _start: read_write 1,1,m1,l1 read_write 0,0,num,3 ; 0 and 0 for read function and 3 because 2 numbers and the enter hit on keyboard call accept_proc ; here the subroutine is called mov rbp,array mov [rbp],bx read_write 1,1,m2,l2 mov ax,bx call display_proc read_write 1,1,num,16 mov rax,60 ; Function no for sys_exit mov rdi,0 ; return 0 syscall accept_proc: mov rsi,num ; point the rsi to the first number mov rbx,0 ; set it to 0 mov rax,0 ; set it to 0 mov rcx,2 ; counter for the 2 numbers ( To keep a count of how many digits have been converted back: rol rbx,04 ; Rotate the bits to left by 4 as after the first digit is converted using whole subroutine, the number is at unit postion so to get it a ten's postion rotate by 4 mov al,[rsi] ; move the content of rsi to al cmp al,39h ; compare with 39h becaue after 39h there are special characters in ascii table for hex jbe next ; jump if below or equal after comaparing sub al,07h ; subtract 07h from the number if greater than 39h as 7 special characters in between next: sub al,30h ; Subtract 30h from al add bx,ax ; add contents of ax to bx inc rsi ; increment rsi that is now point to next number dec rcx ; decrement the counter jnz back ; if counter not zero then go the back ret display_proc: mov rbp,char_ans mov rcx,2 up3: rol al,04 mov dl,al and dl,0Fh cmp dl,09h jbe next1 add dl,07h next1: add dl,30h mov[rbp],dl inc rbp dec rcx jnz up3 read_write 1,1,char_ans,16 read_write 1,1,m3,l3
run
|
edit
|
history
|
help
0
lec4bb.asm
dfsfsafsdfds
Disition
Group Project (Group 4)
dsffsdfsdfds
BranchesLab_mSmith_bBrownV2
fsdffdasf
Psn2
fdafdafdafsfdsa
Little endian n big endian