flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
macomics 30 Nov 2022, 04:22
dw = 16-bit integer -> db 17 dup (0)
Code: inttostr: ; ax = integer, cx = base, out ds:si = buffer push si push bp mov bp, sp test ax, ax jns @f mov byte [si], '-' inc si neg ax @@: xor dx, dx div cx push dx test ax, ax jnz @b @@: pop ax cmp al, 10 jc .num add al, 'A' - '0' - 10 .num: add al, '0' mov [si], al inc si cmp sp, bp jc @b mov byte [si], 0 mov ax, si leave pop si sub ax, si retn ; retf (ax = length) Code: strtoint: ; ds:si = string, cx = base push bx push si xor ax, ax xor bx, bx cmp byte [si], '-' jnz .beg inc si jmp .beg @@: sub bl, '0' cmp bl, 10 jc .num sub bl, 'A' - '0' + 10 cmp bx, cx jae @f .num: mul cx inc si add ax, bx .beg: mov bl, [si] test bl, bl jnz @b @@: pop si pop bx cmp byte [si], '-' jnz @f neg ax @@: retn ; retf (ax = integer) |
|||
![]() |
|
geekbasic@gmx.com 30 Nov 2022, 19:07
I am barely starting to grasp the pointer instructions.
For the ds:si part of the call, do i use LEA SI,[text]? For the cx, what is meant by base? Does this mean I can specify binary, decimal, etc? Or does it mean something else. Reading the manual, I see that "ret is the equivalent for retn." Does this mean that I can use either ret or retn? Is there a difference? I was wondering that the @@, @f and, @b meant. Just looked it up and that's really cool! Anonymous labels. I will start using this feature in my code wherever I can. Thank you! |
|||
![]() |
|
macomics 30 Nov 2022, 20:01
geekbasic@gmx.com wrote: For the ds:si part of the call, do i use LEA SI,[text]? or Code: lds si, [text_ptr] ... label text_ptr dword ; Convert the linear address of text to a segment and offset for 16-bit addressing .off dw .str and 0xFFFF .seg dw (.str and 0xF0000) shr 4 .str db '1234', 0 In 16-bit mode, the following addressing mode operates: each memory cell has a 20-bit linear address, which is divided into 2 components. The first component contains the address of the paragraph (16-byte value, located in the segment register), the second (located in the base or index register or specified directly) - the address of the byte relative to the 64 kb block starting with the paragraph specified in the segment register. A 20-bit address allows access to 1 MB of memory, but such an addressing mechanism creates a collision, due to which about 65520 bytes more are available for addressing (after opening the A20 gate). geekbasic@gmx.com wrote: For the cx, what is meant by base? Does this mean I can specify binary, decimal, etc? geekbasic@gmx.com wrote: Reading the manual, I see that "ret is the equivalent for retn." Does this mean that I can use either ret or retn? Is there a difference? retf is a far return instruction. It reloads from the stack not only the return address (ip), but also the segment address (cs). Only 4 bytes. In order to write retf at the end, it is necessary that the function call be appropriate. For example: Code: call text:inttostr ; far call of the `inttostr` function in the `text` segment There is also an iret - return from an interrupt. It reloads from the stack not only the return address (ip) and segment address (cs), but also the value of the flag register (fl). Only 6 bytes. She also performs additional manipulations with flags. This instruction is mainly used in interrupt vector handlers, but it can also be used when switching tasks in protected mode and changing the privilege level. geekbasic@gmx.com wrote: I was wondering that the @@, @f and, @b meant. Just looked it up and that's really cool! Anonymous labels. I will start using this feature in my code wherever I can. |
|||
![]() |
|
geekbasic@gmx.com 30 Nov 2022, 22:45
Your explanation is helpful. I am now able to make the code work.
Thank you! |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.