New Posts  All Forums:Forum Nav:

assembly lang input

post #1 of 3
Thread Starter 
Hello guys,

To make it short I was given a challenge ( I normally do C++ but we had a debate how hard is assembly) and I was told to make a square and turn it in to a triangle

Ive done that but I wanted to be fancy and see if I can get a user input and then display how long they want the traingle to be (it increments by 1). Is it easy to do? I currently been googling and my brain is stuggling lol

If you want to take a look here it is
Warning: Spoiler! (Click to show)
Code:
;; using a nested loop create a 10 by 10 square
section .data
        global _start
        char db ' ' ; declare char to store dots and newlines
        squaresize db 1        ; 10x10 square

section .text
_start:
        ;; use ax for the row counter
        mov rax, [squaresize]; move squaresize into rax to set the size of the outer loop - rows of square
        outer_loop:
                ;; use ax for the row counter
                mov rbx, rax  ; move squaresize into rbx to set the size of the inner loop - column of square
                inner_loop:
                        ;; draw a dot
                        call dot
                        ;; subtract from the counter
                        ;; and repeat if we haven't hit 0 for inner loop
                        dec bx
                        cmp bx,0
                        jg inner_loop
                ;; go on to next line
                call linefeed
                ;; subtract from the counter
                ;; and repeat if we haven't hit 0 for outer loop        
                inc ax
                cmp ax,10
                jne outer_loop
                ;; go to next line
                call linefeed
                ;; exit cleanly
                call exit
;; Some useful routines that I can call many times
;; or even copy and paste into other code
        
exit:   
        mov eax,1; system call to exit            
        mov ebx,0; exit value             
        int 80h; call kernel with interrupt to exit program
        ret
;; new line code section
linefeed:       
        ;; move newline character into char
        mov [char],  byte 10
        push rax; push rax on to stack to allow outer loop to occur
        push rbx; push rbx on to stack to allow inner loop to occur 
        mov eax,4; system call to write out           
        mov ebx,1; standard out to screen 
        mov ecx, char; go to next line on screen 
        mov edx,1; size of new line
        int 80h; interrupt to kernel to go to next line by looking into registers
        pop rbx; pop rbx on to stack to allow outer loop to occur
        pop rax; pop rax on to stack to allow inner loop to occur 
        ret
        
dot:    

        mov [char],  byte '.'; put dot (.) in char
        push rax; push rax on to stack to allow outer loop to occur
        push rbx; push rbx on to stack to allow inner loop to occur 
        mov eax,4; system call to write out           
        mov ebx,1; standard out to screen 
        mov ecx, char; put dot in register ecx 
        mov edx,1; size of dot in register
        int 80h; interrupt to kernel to print dot on screen by looking into registers         
        pop rbx
        pop rax

        ret 






post #2 of 3
How do you run this?
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #3 of 3
You "compile" it with an assembler.

In practice, it's not that different from compiling other AOT languages.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming