I got displayChar character showing on the boot up. Now how do i add writeHexBytes which then displays on the screen using writeHexByte in a loop, and writeHexWord.
*writeHexByte expects an 8-bit register displays it by calling convertHexNibble and using writeChar
*writeHexWord expects a 16-bit register or memory parameter and displays each byte by calling writeHexByte
so after writing characters it needs to display machine code that macro writeChar implements. And display using writeHexBytes in a loop
Code attempted
# Macro definition
.macro convertHexNibble register
cmpb $10, \register
jl 1f
# process here is >=10
add $0x37, \register
jmp 2f
# process here is <=10
1:
add $0x30, \register
2:
# expect the register to now be the ascii code
.endm
#.macro writeHexByte register
#convert
#.endm
.macro displayChar character color
mov $0x09, %ah
mov \character, %al
mov $0x00, %bh
mov \color, %bl
mov $0x01, %cx
int $0x10
.endm
#set defualts values to move cursor off screen
.macro moveCursor row = $0xff column = $0xff
mov $0x02, %ah # ah = 02h moves the cursor row 2 col 2
mov $0x00, %bh # bh = 0 page
mov $0x02, %dh
mov $0x02, %dl # dl=1
int $0x10
.endm
.macro sumArray array number result
# assume array is an array of bytes
#therefore the accumulator is just %al (8bits)
mov $\number, %cx # AX will serve as a counter for
# the number of words left to be summed
mov $0, %ax # BX will store the sum
mov \array, %bx # CX will point to the current
# element to be summed
top: add (%bx), %cx
inc %bx # move pointer to next element
dec %ax # decrement counter
jnz top # if counter not 0, then loop again
done: mov %ax, \result # done, store result in "array"
.endm
# The main boot processing code
.code16
.text
.global _start
_start:
mov $06, %al
convertHexNibble %al
displayChar %al, $0xe3
moveCursor %ah
mov $0x0A, %al
convertHexNibble %al
displayChar %al, $0xe3
sumArray $x 4 sum
# writtenHexWord $sum
# move Cursor off screen invisble
moveCursor
cli # clear interrupts
hlt
x: .byte 1, 5, 2, 10
# char x[] = {1, 5, 2, 10};
sum: .byte 0
# char sum = 0;
. = _start + 510
.byte 0x55
.byte 0xAA