Download presentation
Presentation is loading. Please wait.
1
An “interactive” application An introduction to “structured” assembly language programming
2
A human-computer dialogue Typical pattern: –Computer asks a question –Human types in a response Simple example: –Computer says: How many dots? –Human replies: 125 –Computer does as requested.
3
Standard C functions How can we do input/output in assembly? We can call standard C library functions But we need to know their “prototypes” For output (where STDOUT equals 1): write( STDOUT, &query, sizeof( query ) ); For input (where STDIN equals 0): read( STDIN, &buffer, sizeof( buffer ) );
4
Structured programming A discipline for faster program design Idea: break a big task into simple pieces It’s known as “task decomposition” We can use a diagram to illustrate it Diagram is called a “Structure Chart”
5
Structure Chart example main process_dataprint_outputobtain_input
6
Code for the ‘main’ function.section.text main:callobtain_input callprocess_data callprint_output ret.globlmain
7
Stubs You can write empty ‘stubs’ (for testing) obtain_input:ret process_data:ret print_output:ret Now you can ‘test’ your skeleton program (e.g. assemble, link, and execute)
8
Add details for each ‘stub’ First write your final subroutine, so you can see “something” on the screen You can use ‘dummy’ data temporarily Get it working correctly (debugged) Then you can focus on you next ‘stub’
9
Main algorithm Converting user’s input-string to a number That is “the hard part” in this example Idea: “scan” the array of character-codes Test each code (to see if it’s a valid digit) It must lie between ‘0’ and ‘9’ (ascii codes) If code is not not valid, the scanning stops Otherwise, adjust the accumulated total
10
Some new directives.ascii.asciz.long.byte.space
11
Some new CPU instructions sub dec cmp jg jl jz jnz movzx loop imul
12
Exercise with ASCII codes See what happens if you change the ascii code used for as value of the ‘dot’ variable Try using ascii value 7 Try using ascii value 9 Try using ascii value 10 Try using ascii value 111 Try using ascii value 250
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.